javascript - How to Destroy Active Routing Component from another component in angular - TagMerge
2How to Destroy Active Routing Component from another component in angularHow to Destroy Active Routing Component from another component in angular

How to Destroy Active Routing Component from another component in angular

Asked 10 months ago
1
2 answers

I suppose this is how angular routing works. when you try to navigate to the same URL you currently are, angular ignores the navigation by default. anyhow there is an ExtraOptions object you can specify on angular routing module like described below:

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

link to angular documentation

You may think by providing this option, angular resets state of the component (or reloads the page) but this does not work as you want neither. Routing in angular does not primarily re-instantiate your components and it doesn't have to. if you want to do some special work while navigating to the current URL, a workaround is to subscribe to router events. something like this:

  ngOnInit(): void {
    this.router.events.subscribe(event => {
      if (event instanceof NavigationEnd) {
        // do your checks and call your special function/method
      }
    })
  }

Source: link

0

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

Source: link

Recent Questions on javascript

    Programming Languages