ui-router unexpectedly cuts href value in a <base> tag
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
I think it's intended to end in / so
<base href="/application/">
should work
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.
I can confirm this is a bug. Looking into it
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?
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 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)
It should do a check if its a slash and only slice it then