angular: Router no longer navigates when navigating to the current URL.
I’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When navigating to the current URL, the route is not reloaded and no navigation events are fired.
Expected behavior
The router should navigate to the route, firing the navigation events.
Minimal reproduction of the problem with instructions
Plunker: http://plnkr.co/edit/TlRwYcDmV0JacgD9UgFU?p=preview
Click the link for the current page and note the events don’t fire.
What is the motivation / use case for changing the behavior?
My specific case is that I have been using the router events to enable me to scroll the page back to the top when the NavigationEnd event is fired. This no longer gets fired when navigating to the current URL and so when someone is on my home page and scrolls down to the bottom, if they click a home link it doesn’t scroll them back to the top. Also, if this were running as a standard website, the page would reload in this circumstance. This used to work absolutely fine but has since changed after upgrading.
At the very least it would be good to be able to have an option when initialising the routes to change this behaviour.
- Angular version: 2.3.0
- Browser: all
-
Language: all
-
Node (for AoT issues):
node --version
=
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 12
- Comments: 15 (6 by maintainers)
Links to this issue
Commits related to this issue
- fix(router): navigating to the current location works Closes #13340 — committed to vsavkin/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works Closes #13340 — committed to vsavkin/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works Closes #13340 — committed to vsavkin/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works (#19463) Closes #13340 PR Close #19463 — committed to chuckjaz/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works (#19463) Closes #13340 PR Close #19463 — committed to chuckjaz/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works Closes #13340 — committed to vsavkin/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works (#19463) Closes #13340 PR Close #19463 — committed to matsko/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works (#19463) Closes #13340 PR Close #19463 — committed to jmleoni/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works (#19463) Closes #13340 PR Close #19463 — committed to jmleoni/angular by vsavkin 7 years ago
- fix(router): navigating to the current location works (#19463) Closes #13340 PR Close #19463 — committed to jmleoni/angular by vsavkin 7 years ago
This seems like an end developer error, but yes, if a guard rejects navigation then stay where you are and do nothing else.
I guess it would depend on
runGuardsAndResolvers
setting.How about at least 2, maybe 3 ways to set this 😃
and one or both of the following to override module level setting:
ExtraOptions
to be set at route definitionrouterLink
andnavigate()
to be set a call siteWhy navigate to same route
I think this is what most everyone expects, end users and developers alike. My specific use case is for settings screens like the one in github.
If you click
Options
on the left, pretty much everyone expects the form to reset (and usually with updated data if there are updates). The same withSettings
up top (except it would also take you back toOptions
if you were on a different settings page). Ideally, there shouldn’t be anything (or very little) a dev has to do to get this behavior.@Kriskit Firing some sort of event is a good idea. Maybe “IgnoredNavigation” or something like that.
I would love to see this reviewed again. The
IgnoredNavigation
event would work well for our use case.The router is a state machine.
Being able to navigate to the “current state” might lead to confusing behaviour. For example, consider this scenario:
Also, we are considering rerunning resolvers every time a navigation happens, which won’t work with your use case as well.
I think we should either always allow it, or never allow it, so don’t have an extra option.
Is it just the scrolling you are concerned about? If so, maybe it’s better to have a directive with this selector
[routerLink]
that will force the scrolling?As far as I can see, this issue is closed, but the “navigations” Observable in the router is private. Is there another feature request or way of allowing a end-user to listen to navigation.
My use case is a single component (enclosing an iframe) that needs to reset its state (iframe’s URL) when the user clicks on a link toward the current page. Having a directive override
[routerLink]
for my whole application seems a bit overkill…In my case, being able to override
onSameUrlNavigation
on a per-route basis would be perfect (actually)…It looks like the NavigationStart event occurs after urlHandlingStrategy.shouldProcessUrl(rawUrl), I have been of the school of thought that you fire a start event then you do stuff, in this implementation stuff is done (shouldProcessUrl) before the start event. NavigationStart should be renamed to RoutingStart and NavigationStart should fire immediately after any navigation event.
I understand what you’re saying but it still feels like the router should at least tell us something, even if it was a
NavigationCancel
event. At present, despite a call being made to the router to navigate (through a[routerLink]
click or otherwise) no events get fired at all.I’m not convinced using a
[routerLink]
selector directive would cover everything I need it to do but I will give it a try, although feels like a workaround.This used to work fine, and saw nothing in the change logs to suggest there was a breaking change regarding this so viewed it as a bug.