ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

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

Open TheProdigyFilippo opened this issue 11 years ago • 7 comments

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

TheProdigyFilippo avatar Nov 04 '15 13:11 TheProdigyFilippo

I think it's intended to end in / so

<base href="/application/"> 

should work

IainCole avatar Nov 04 '15 13:11 IainCole

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.

TheProdigyFilippo avatar Nov 04 '15 13:11 TheProdigyFilippo

I can confirm this is a bug. Looking into it

eddiemonge avatar Nov 06 '15 19:11 eddiemonge

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?

eddiemonge avatar Nov 06 '15 20:11 eddiemonge

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.

tsonev avatar Dec 01 '15 08:12 tsonev

@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)

christopherthielen avatar Mar 17 '16 15:03 christopherthielen

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

eddiemonge avatar Mar 17 '16 17:03 eddiemonge