xxxxxxxxxx
@Component({
selector: 'app-my-component',
template: '<p>My Component Content</p>'
})
export class MyComponent implements OnInit {
constructor(private router: Router, private route: ActivatedRoute) {}
ngOnInit(): void {
// Subscribe to route changes
this.router.events.pipe(
filter(event => event instanceof NavigationEnd)
).subscribe((event: NavigationEnd) => {
// Perform actions when route changes
console.log('Route changed:', event.url);
// Add your custom logic here
});
}
}