Search code examples
angularangular-routing

Navigating to the same route with different parameters


I navigate in the typescript file with

this.router.navigateByUrl(`account-transactions/${code}`);

however, my active route is

http://localhost:4200/account-transactions/10102

but if try to navigate to, say:

http://localhost:4200/account-transactions/99999

the url address changes, but the component is not reloaded

Anyone knows why?


Solution

  • I think you are using snapshot to get your value, so in order to work you need to user Activated Route so you can subscribe to detect changes in your routing You should change your init code for the following:

    constructor(private route: ActivatedRoute) {}
    
      ngOnInit() {
       this.route.params.subscribe(params => {
           this.id = params['id']; //or whatever you put in your routing
           // here your logic to use this id
    
        });
      }