app.component.ts
export class AppComponent implements OnInit { previousUrl: any; constructor(private render: Renderer2, private router: Router) { this.router.events.subscribe( (event) => { if (event instanceof NavigationStart) { //for current page name let currentUrlSlug = event.url.slice(1); let currentUrlSlug2 = 'fixed-inner'; if (this.previousUrl) { console.log('hit'); this.render.removeClass(document.body, currentUrlSlug2); } if (currentUrlSlug) { this.render.addClass(document.body, currentUrlSlug2); } this.previousUrl = currentUrlSlug; } } ) } }
Now this fixed-inner class always show only on inner pages