user2736022 user2736022 - 4 years ago 183
HTML Question

Angular2 router 2.0.0 not reloading components when same url loaded with different parameters?

I have this in my .routing.ts file

export const routing = RouterModule.forChild([
path: 'page/:id',
component: PageComponent

file checks the id parameter and loads the data accordingly. In previous versions of the router, if i went from /page/4 to /page/25, the page would "reload" and the components would update.

Now when i try navigating to /page/X where X is the id, it only ever loads the first time, then the url changes, but the components do not "reload" again.

Is there something that needs to be passed in to force my components to reload, and call the ngOnInit event?

Answer Source


That's now fixed (Angular 2.3) for the new router by which allows to provide a custom reuse strategy.

For an example see also


That's a known issue. Currently there is no way to make the router re-create the component on parameter-only route changes.

They discussed plans to implement some reuse-strategies eventually.

You can subscribe to params changes and execute your code there instead of in ngOnInit()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download