You need to handle this inside the component or based on a variable, you can use url property of the router to get the current component url
constructor(router: Router) {
this.router.events.subscribe((event: Event) => {
console.log(event.url); //based on this change class
});
}