Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRouter: Provide support for handling the URL hash #6595
Comments
|
+1 |
|
Do we have any update on this? |
|
Yes, I need this really quick as well. |
|
+1 please fix. This is mandatory for md-tab routing as well. |
|
Are there any plans on this ? I was thinking on a few scenarios in my angular 2 prod app. As for designing a solution, will it makes sense to have these values on each route in @RouteConfig as well as when the user uses router.navigate(). The user should be allowed to navigate to a position or #hash, by default to the top (0,0) It may look something like:
and on
I believe we need changes in This or any other better solutions we implement, will it jump to the position or scroll smooth to the specified position. Idk. |
|
+1 |
|
+1 (#8105) |
|
Support for fragments has been added to the v3 router |
|
The router at release Let's assume you are at this location: Then clicking this link: will update the browser's url to: So far, so good. However, the view does not automatically scroll/jump to the element with id "Test". Are there any plans to fix this or am I just missing something? |
|
Using How can I retrieve the fragment in |
|
Found the answer: http://victorsavkin.com/post/145672529346/angular-router
|
|
@mark-langer did you ever get this working? Stuck in the same place where the #fragment works in the link but browser doesn't scroll to the id location. |
|
Nope, I just stumbled upon this issue on stackoverflow. I didn't need to fix this for my own application. I haven't tried it since alpha.8, though. Have you tried if this works with RC.5? |
|
It’s creating the #fragment in the route but not navigating to it via the angular router (v3) and I’m in RC4 currently. On page refresh it works, but that kind of defeats the point. From: Mark Langer notifications@github.com Nope, I just stumbled upon this issue on stackoverflow. I didn't need to fix this for my own application. I haven't tried it since alpha.8, though. Have you tried if this works with RC.5? — {"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/angular/angular","title":"angular/angular","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/angular/angular"}},"updates":{"snippets":[{"icon":"PERSON","message":"@mark-langer in #6595: Nope, I just stumbled upon this issue on stackoverflow. I didn't need to fix this for my own application. I haven't tried it since alpha.8, though. Have you tried if this works with RC.5?"}],"action":{"name":"View Issue","url":"https://github.com/angular/angular/issues/6595#issuecomment-241527913"}}} |
|
Yes, absolutely agreed. Maybe the Chuck Norris of routing, @brandonroberts, can help? |
For documentation, see `RouterModule.scrollPositionRestoration` Fixes angular#13636 angular#10929 angular#7791 angular#6595
|
Fixed via #20030 |
|
@brandonroberts I'm confused. You say this is "fixed", pointing to a patch which restores scroll position when returning to a page, but isn't this issue (see the title) originally about correct handling of hashes (fragments), or am I missing something? |
|
@rtm the PR adds support for handling fragments in addition to restoring thr scroll position when navigating between pages. |
|
So this isn't fixed... Or mistitled |
|
@SteamWind This issue is only about scroll position, so what do you expect? |
|
Maybe I misunderstood. Is it now possible to scroll to an hash when your already on the same route? |
|
Fragments are also part of the URL: angular/packages/router/test/bootstrap.spec.ts Lines 312 to 318 in 15e671e |
|
@trotyl, this is not just about the scroll position. This is about 'Provide support for handling the URL hash' as described in the beginning. IMO, this has not been addressed properly. Take this example. This is most commonly handled by a skip-link. In my example, I've made the skip-link visible and then pushed everything down. If I try to use the |
|
@MrGrigri URL hash is about scroll position, isn't it? Or what are the other semantics a fragment defined by standards? And that's what anchorScroll feature meant for. If you have extra assumption about the fragment, that's already your own business logic. It could be fine to open new feature request for them, but which is indeed not part of this issue talking about:
|
|
Thanks @trotyl, I wasn't aware of the Should I open a new issue to cover these two? |
|
It's a browser bug that |
|
And what about the focus? It should focus the targeted element so when the tab key is pressed on the keyboard it continues from there. This is critical for accessibility. |
|
Sounds reasonable to me, better to open a new feature request for focusing behavior. It would likely also be put behind a flag for non-breaking requirement. |
|
i did as following in about-us.component.html hash is not adding in router. i am new bee in angular. :) |
issue resolve. i did it as following :- first i remove routerLink from a tag and add function on it . and in the function and the result is |
|
I am doing what @phutaneVinayak suggested, and I do see the URL update with the fragment, but I do not see it scroll to that fragment's corresponding element. Here's an example. Both of these produce the fragment in the URL, but neither seems to scroll the page: this.router.navigate(['/'], { fragment: 'test' });this.location.go('#test');I know the HTML element is ID'd correctly because if I click in the address bar and hit Enter, it works. |
Hi @cbejensen. I am working on your stackBiltz, seem you are using angular 4 and it does not provide options in routing config. so it will not definitely scroll to that id element. I need to find some workaround for that. give some time
HappyCoding |
Hi, @cbejensen
|
You don't even need the hash for that.. for me that looks elegant (but idk if it's good practice to navigate within pages without indicating it in URL)..
Is also working.. but not if you want to navigate directly to a position of a page, coming from a different route.. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
If I have a URL with a hash, when I navigate to it, the hash is dropped from the URL and the page does not jump to the anchor tag. If I have to go an existing route and click a link with the hash at the end, it jumps to the anchor tag correctly. Also, their isn't a public api to get/set the hash outside of using
window.location.hash