Skip to content

When using "base href" ui-router generates wrong urls #638

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
drozzy opened this issue Dec 5, 2013 · 14 comments
Closed

When using "base href" ui-router generates wrong urls #638

drozzy opened this issue Dec 5, 2013 · 14 comments

Comments

@drozzy
Copy link

drozzy commented Dec 5, 2013

Proper urls are not generated properly by ui-sref when <base href="/foo/bar/" /> is present.

My angular app is hosted in the foo/bar directory.
In my index.html:

<base href="/foo/bar/" />

my routes are like:

.state('mystate', {
        url: '/statelocation',
        ... })

and here is how I reference the state in the template:

<a ui-sref='mystate'>Go to my state!</a>

And instead of outputting:

<a href="statelocation">Go to my state!</a>

I get (note the slash):

<a href="/statelocation">Go to my state!</a>
@nissoh
Copy link
Contributor

nissoh commented Dec 19, 2013

if you're not worried about xss, document.write('<base href="' + document.location + '" />'); might help.

you could generate the location via generated script by the server aswell

@dlukez
Copy link
Contributor

dlukez commented Dec 20, 2013

What happens if you remove the slash from the state declaration?

@anton000
Copy link

same issue here

@bstruthers
Copy link

@dlukez If you remove the slash, the URL generated is correct. However, the URL routing breaks because it can no longer match that route.

@ezpuzz
Copy link

ezpuzz commented Feb 1, 2014

Having the same issue

@nateabele
Copy link
Contributor

Can you show me a page that demonstrates the issue?

@Guuz
Copy link

Guuz commented Feb 17, 2014

Same issue here.
For example my base tag could look like this:

<base href="/en/"/>

The app works with ui-router. Clicking links is handled correctly and only the part in the url after /en/ is updated by angular (ui router).
But for instance when I CTRL click (new tab) the generated URL does not contain the language (base href).

Screenshot showing a hover on "more details":
image

Is this enough information? I really need to find a fix or workaround because this bug is breaking the app and we can't have that.

@timkindberg
Copy link
Contributor

Will be fixed in next release by #528

@Guuz
Copy link

Guuz commented Feb 24, 2014

@timkindberg
Thanks for this!
Any estimate on when there will be a new release? Else I will have to cherry pick this fix and I would rather not do that.

@timkindberg
Copy link
Contributor

Couple weeks?

@Guuz
Copy link

Guuz commented Feb 24, 2014

Ok. That's probably too long for us to wait. I'll have to see if I can patch v0.2.8 with this fix and use that until the next release.
Thanks though!

@nateabele
Copy link
Contributor

Any estimate on when there will be a new release?

@Guuz Two hours ago.

@Guuz
Copy link

Guuz commented Mar 13, 2014

Thanks! That's a pretty good estimate ;-)

@catazep
Copy link

catazep commented Mar 14, 2017

I am not sure you have the same problem as I do, but this issue ruined my day, and after hours of trying to fix it beautiful I used this workaround http://stackoverflow.com/questions/34211894/angular-ui-router-ui-sref-links-arent-prepending-the-hash-when-filling-in-href/34775725#34775725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants