0

I have a notification module ,in that module i should redirect user to other pages for showing notification detail .

I have a problem with this :

when i enter this route payment/detail/1254 for first time , every thing is ok , but then i need to change route to this for show other notification detail payment/detail/8547 , the route changes , but the page not change not show me previous detail .

i know i can use this code in every component i need :

  router.events.subscribe((val) => {
    // see also 
    console.log(val instanceof NavigationEnd) 
});

but i have a more than 40 modules . i want use the this code in common place , i need write this code or same code in the common place and I do not have this problem every time the route changes.

how can i solve this problem ???

1
  • would you mind building a stackbit.com minimal example showing the problem you are facing? Commented Jun 28, 2021 at 5:07

1 Answer 1

0

Problem: you navigate from route A to route A with different parameters. this causes the router to not do anything, by default, as you're navigating to the same page.

Possible solutions:

One approach would be to subscribe to ActivatedRoute's paramMap and fetch the details every time it emits. preferably piped with distinctUntilChanged() to avoid reloading the page when navigating to same page with same parameter.

constructor(private route: ActivatedRoute)

ngOnInit() {
    this.route.paramMap
     .pipe(distinctUntilChanged((prev, curr) => prev.id === curr.id))
     .subscribe(({id}) => this.getDetails(id));
}

a Different approach would be to configure your router to reload when navigating to the same route.

     @NgModule({
       imports: [
           RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload' })
       ],
       exports: [RouterModule],
     })

This obviously might add a performance hit, depending on your architecture.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.