Problem with switching links in Angular
Let's look at a solution to the problem with switching links in routing. This problem can be solved using the RxJS library, which is already included in Angular.
First, let's import the Subscription class:
import { Subscription } from 'rxjs';
Let's make a private property:
export class AaaaComponent {
private subscription: Subscription;
}
Let's create a property to store a parameter named id:
export class AaaaComponent {
id: number | undefined;
private subscription: Subscription;
}
Now let's subscribe to the change of the id parameter from the route:
export class AaaaComponent {
id: number | undefined;
private subscription: Subscription;
constructor(private activateRoute: ActivatedRoute) {
this.subscription = activateRoute.params.subscribe(params => this.id = params['id']);
}
}
Fix the problem with switching links.