Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  6] [ 4]  / answers: 1 / hits: 29827  / 8 Years ago, fri, september 16, 2016, 12:00:00

I have this in my .routing.ts file



export const routing = RouterModule.forChild([
{
path: 'page/:id',
component: PageComponent
}]);


My 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?


More From » html

 Answers
52

update 2



This answer is only for a long ago discontinued router version.



See https://angular.io/api/router/RouteReuseStrategy for how to do it in the current router.



update 1



That's now fixed (Angular 2.3) for the new router by https://github.com/angular/angular/pull/13124 which allows to provide a custom reuse strategy.



For an example see also https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx



original



https://github.com/angular/angular/issues/9811



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()


[#60699] Tuesday, September 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiley

Total Points: 733
Total Questions: 118
Total Answers: 94

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;