Skip to content

feat($state): support URLs with #fragments #1867

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

Merged
merged 1 commit into from
Apr 8, 2015
Merged

feat($state): support URLs with #fragments #1867

merged 1 commit into from
Apr 8, 2015

Conversation

mismith
Copy link

@mismith mismith commented Apr 8, 2015

Allow setting the # param to update the location fragment; e.g.: ui-sref="page({name: 'name', '#': 'frag'})" or $state.go('page', {name: 'name', '#': 'frag'})

Improving upon #1855

Allow setting the `#` param to update the location fragment; e.g.: `ui-sref="page({name: 'name', '#': 'frag'})"` or `$state.go('page', {name: 'name', '#': 'frag'})`
@nateabele
Copy link
Contributor

Patch looks good. 👍 I'll just wait for Travis to do its thing.

nateabele added a commit that referenced this pull request Apr 8, 2015
feat($state): support URLs with #fragments
@nateabele nateabele merged commit 2fff59c into angular-ui:master Apr 8, 2015
@qdb
Copy link

qdb commented Apr 22, 2015

Hi there,

Any idea when we can expect release version with this update?

@mismith
Copy link
Author

mismith commented Apr 29, 2015

Looks like it's in 0.2.14 now :) Thanks ui-router team!

levity added a commit to Hylozoic/hylo-frontend that referenced this pull request May 10, 2015
to get hash fragment support:
angular-ui/ui-router#1867
@christopherthielen christopherthielen added this to the 0.2.14 milestone May 19, 2015
@kikar
Copy link

kikar commented May 27, 2015

It doesn't seem to work for me.

This is the anchor:
<a id="pricing">Pricing</a>

And this is the link:
<a ui-sref="public.home('#': 'pricing')">PRICING</a>

Do I have to change something else?

@nateabele
Copy link
Contributor

@kikar You forgot the { ... }:

<a ui-sref="public.home({ '#': 'pricing' })">PRICING</a>

@kikar
Copy link

kikar commented May 27, 2015

@nateabele Still not working, goes to right page, but doesn't scroll to anchor nor changes the url.
Is it a problem if the anchor is in a subview, and the link is in the parent view?

@alexlawrence
Copy link

@nateabele @kikar Same here. Goes to the right page but does not jump to the anchor.

@nateabele
Copy link
Contributor

Not sure. Can you open a new issue with a link to a plunkr that demonstrates the issue? Thanks.

@vike27
Copy link

vike27 commented Jul 25, 2015

Not working for me either, goes to correct page with correct fragment but does not jump to anchor.

<a id="yoh">GOING HERE!<a> 
<a class="pull-right" ui-sref="reserve({ '#':'yoh' })"><strong>Edit</strong></a>

@NateEag
Copy link

NateEag commented Aug 16, 2015

@nateabele - #1961 was (wrongly) closed as a duplicate of #701, and has a Plunkr demonstrating this exact issue in version 0.2.14:

http://plnkr.co/edit/6KM0DRXB38gcGjgYkgjd?p=preview

@chedched
Copy link

Same problem here.

@qdb
Copy link

qdb commented Oct 14, 2015

Guys,

I think it is not going to work the way you expect. As far as I understand router code, the ui-sref transitions to new state on click, which usually means load new view or subview and run associated controller. It does not handle scrolling for you (except for autoscroll to view mentioned below). I believe you need to scroll to the given element yourself using something like https://docs.angularjs.org/api/ng/service/$anchorScroll

Things to consider:

  1. scrolling can be hijacked by the router itself if you use autoscroll https://github.com/angular-ui/ui-router/wiki/Quick-Reference#autoscroll
    I am not sure what happens if you try to use both router autoscroll and angular's native method at the same time. I think you should not.

  2. Make sure to scroll after your DOM renders Otherwise you may scroll to wrong position. This can sometimes be achived using $timeout with 0 seconds, but if you load images, it can be more tricky.

Good luck

@klmdb
Copy link

klmdb commented Nov 10, 2015

Does anyone know how to get this working with smooth scrolling please?

@Sekhno
Copy link

Sekhno commented Mar 8, 2016

Thank you!

@lookfirst
Copy link

Let's say you have a link on Page A in the common footer of the page:

<a ui-sref="root.support.index({'#': 'top'})" ui-sref-active="active">Help</a>

You then click on that link to take you to Page B root.support.index. When you click on the link, the ui-sref-active isn't re-evaluated, so the link stays active on the next page.

This works fine when the argument ({'#': 'top'}) is removed or if Page B is reloaded in the browser.

@egomezv91
Copy link

egomezv91 commented Jul 28, 2016

For me it doesn't work, I have te same problem who lookfirst, the first time it go to the Page B but don't scroll and if you reload the browser, or go back and press the link again it work good. I wait new comments and if someone can find a solution. Thanks in advance

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

Successfully merging this pull request may close these issues.