简体   繁体   中英

Angular2 router doesn't change component

I have 1 component that I want to reuse for different router links there routes look like:

{ path: '', component: OddComponent },
{ path: 'sport/:id', component: OddComponent },
{ path: 'sport/:id/category/:categoryid', component: OddComponent }

The component needs to fetch from different places with every router link. The problem is the component subscribes to a service and now every time I navigate to a different router link the subscriptions stack up. How can I fix this problem?

you can use the onDestroy hook to unsubscribe from the service before changing the route ...

for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM