Router.renavigate() doesn't work with Router.navigate()
See original GitHub issueWe are on alpha 54.
With AngularJS, we used $state.go($state.current.name, $state.params, {reload: true});
to reload the contents of our app when we received a notification of stale data from the server. We’re trying to use router.renavigate()
in Angular to solve the same problem, but it’s not working for us.
The problem is that router.renavigate()
uses the last url it was given (stored in router.lastNavigationAttempt
), but not all methods of navigation set that value. router.lastNavigationAttempt
is set when entering a url in the browser directly, or when using the discouraged router.navigateByUrl(...)
, but not when using the encouraged router.navigate(...)
or router.navigateByInstruction(...)
.
The effect is that calling router.renavigate()
doesn’t necessarily reload the current page - it often reloads another page that happens to be the starting point of the app or just some other place in the app on which I hit F5.
I created a Plunker to demonstrate the issue. Follow these steps:
- Click on the ‘Nested Page by Url’ button, which uses
router.navigateByUrl(...)
. The public behavior is that the bottom of the app now shows ‘Nested Page’. You’ll also see at the top thatrouter.lastNavigationAttempt
changes to/nested/page
. - Click on the ‘Home’ button, which uses
router.navigate(...)
or use the ‘Home’ link. The public behavior is that the bottom of the app now shows ‘Home’. You’ll also see at the top thatrouter.lastNavigationAttempt
still shows/nested/page
. - Click on the ‘Reload’ button, which uses
router.renavigate()
. You’ll see that the bottom of the page changes back to ‘Nested Page’ becauserenavigate
uses the stalelastNavigationAttempt
. My intent was to reload the ‘Home’ public value, not to have it change.
We need a way to renavigate that honors routing that happened via router.navigate(...)
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
@brandonroberts That’s a great, simple workaround.
Thanks
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.