Search code examples
angularrxjssubject-observer

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?


Solution

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

    for more details