question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router.renavigate() doesn't work with Router.navigate()

See original GitHub issue

We 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:

  1. 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 that router.lastNavigationAttempt changes to /nested/page.
  2. 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 that router.lastNavigationAttempt still shows /nested/page.
  3. Click on the ‘Reload’ button, which uses router.renavigate(). You’ll see that the bottom of the page changes back to ‘Nested Page’ because renavigate uses the stale lastNavigationAttempt. 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:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
LMFinneycommented, Dec 16, 2015

@brandonroberts That’s a great, simple workaround.

Thanks

0reactions
angular-automatic-lock-bot[bot]commented, Sep 9, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 5 router.navigate does not work - Stack Overflow
Try this this.router.navigate(['. ... Routes = [ { path: 'home', component: HomeComponent } ]; export const routing = RouterModule.
Read more >
Using router.navigate to navigate to another component does ...
Same problem for me i use Angular 6 on Ionic v4 this code in goBach() function doesn't work. goBack() : void{ this.ngZone.run(() =>...
Read more >
Angular 13 Router Navigate: The Complete Guide
To navigate different routes, Angular router provides methods that can navigate different routes using routerLink and programmatically.
Read more >
Common Routing Tasks - Angular
This topic describes how to implement many of the common tasks associated with adding the Angular router to your application.
Read more >
Router navigate not working : r/Angular2 - Reddit
I am trying to use the router.navigate() function with not much success. I am currently on a url localhost:4200/login but when I call ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found