Skip to content
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

Prepend the baseHref to $state.href() generated urls if it exists. #528

Merged
merged 1 commit into from
Feb 17, 2014
Merged

Conversation

tgecho
Copy link
Contributor

@tgecho tgecho commented Oct 25, 2013

I have an angular app that is served from a subdirectory. I have a <base href="/app/"> tag, however the urls generated by the ui-sref directive and $state.href() do not reflect this. The ui-sref links themselves will still work if left clicked, however middle clicking to open in a new tab does not work since the url is missing the contents of the base href.

I think this pretty much covers things the various scenarios...

@nateabele
Copy link
Contributor

It'd be better if the value was pre-calculated and cached outside the function.

@nateabele
Copy link
Contributor

Looks like some other stuff needs to be mocked properly in order for the tests to pass. Please squash your commits when done. Thanks.

@tgecho
Copy link
Contributor Author

tgecho commented Oct 31, 2013

That's strange... the tests passed on my end. Oh well, I'll figure it out. Thanks!

@mfield
Copy link

mfield commented Dec 21, 2013

Someone noticed me futzing with baseHref in a code review and wanted to know what's up. Instead of answering him, I thought I'd chime in here.

If you put the test in its own suite, you can set up the mock in a beforeEach to get it set up before the baseHref gets cached in $stateProvider.$get. The test passes locally after that change (but didn't with the original branch -- not sure why it did for @tgecho).

Check it out at https://github.com/mfield/ui-router/compare/basehref or I can make another PR if that's better.

If an angular app is placed in a subdirectory and a <base href="..." /> tag is used, ui-router should use the configured value when generating urls through $state.href(). Thanks to @mfield for the testing help!
@anton000
Copy link

+1 this should solve #638

@Guuz
Copy link

Guuz commented Feb 17, 2014

👍

nateabele added a commit that referenced this pull request Feb 17, 2014
Prepend the baseHref to $state.href() generated urls if it exists.
@nateabele nateabele merged commit 8ab9778 into angular-ui:master Feb 17, 2014
@Guuz
Copy link

Guuz commented Feb 18, 2014

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.

@samypr100
Copy link

Is there any option I can turn automatic prefixing of the base URL off? or make it configurable ui-sref-option like "prefixBase: false"? Thanks!

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

Successfully merging this pull request may close these issues.

6 participants