Skip to content

ui-router unexpectedly cuts href value in a <base> tag #2357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheProdigyFilippo opened this issue Nov 4, 2015 · 7 comments
Closed

ui-router unexpectedly cuts href value in a <base> tag #2357

TheProdigyFilippo opened this issue Nov 4, 2015 · 7 comments
Labels
Milestone

Comments

@TheProdigyFilippo
Copy link

Hello,

During my work on making angular app SEO friendly and replacing '#' with html5mode, I've noticed that ui-router cuts base href's last letter resulting in unusable application. For example when we set

<base href="/application">

hyperlinks <a ui-sref="someState" results in http://domain/applicatio/someState instead of http://domain/application/someState. It eats 'n'. Generaly it eats last letter no matter what we have in href.

Example available in plunkr: http://plnkr.co/edit/Gl7hVXA64ssfunHCt7ib?p=preview

@IainCole
Copy link

IainCole commented Nov 4, 2015

I think it's intended to end in / so

<base href="/application/"> 

should work

@TheProdigyFilippo
Copy link
Author

Unfortunately it does not work. You can check this in plunker app linked above. Normally it is not required to add '/' at the end and it is not good solution forcing users to add '/' at the end. Standard angular router works ok, but of course I prefer to use ui-router because of all states management.

@eddiemonge eddiemonge added the bug label Nov 6, 2015
@eddiemonge
Copy link
Contributor

I can confirm this is a bug. Looking into it

@eddiemonge
Copy link
Contributor

Seems to be because of this: https://github.com/angular-ui/ui-router/blob/legacy/src/urlRouter.js#L274
Don't know why its chopping off the last character. isHtml5 isn't adding a character here so not sure. @christopherthielen is this fixed or avoided in 1.0?

@tsonev
Copy link

tsonev commented Dec 1, 2015

We are also facing issues with this, as our base tag points to a specific file
<base href="app/app.html">
which seems to be valid declaration according to(and so far has been working fine):
https://docs.angularjs.org/guide/$location#browser-in-html5-mode

and in our case whenever composing hrefs using ui-sref="{'module':'some','app':'myapp'}" we get a href="app/app.htm/some/myapp"

the last character is spliced and it forms an invalid href.

@christopherthielen
Copy link
Contributor

@christopherthielen is this fixed or avoided in 1.0?

No, I haven't changed anything in there.

not good solution forcing users to add '/' at the end

I'm not sure why we're splicing the last character off, but your guess seems plausible (to remove a trailing slash). When the base does end in a slash, does it still make sense to chop it off? If so, this should be a pretty easy PR (only slice if the string ends with a / and add a unit test)

@eddiemonge
Copy link
Contributor

It should do a check if its a slash and only slice it then

@christopherthielen christopherthielen added this to the 1.0.7 milestone Sep 23, 2017
wawyed pushed a commit to wawyed/core that referenced this issue Mar 3, 2018
This fixes the vanilla PushState location service handling of `base` tags.
This change attempts to match the behavior of https://html.spec.whatwg.org/dev/semantics.html#the-base-element
If a base tag is '/base/index.html' and a state with a URL of '/foo' is activated, the URL will be '/base/foo'.
If the url exactly matches the base tag, it will route to the state matching '/'.

This also addresses a longstanding bug where base tags which didn't end in a slash (such as '/base')
had their last character stripped (i.e., '/bas'), and therefore didn't work.
Now base tags like that should work as described above.

Closes ui-router#54
Closes angular-ui/ui-router#2357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants