I'm using router.event.subscribe @angular/router to watch the url change to execute an if statement though event.subscribe works fine. But my question is how can I avoid repeating my if statement just to show the title on these urls. It's probably something else than router.subscribe but not sure what to use for this.
basically wanted a dynamic title based on the url you are on.
this._router.events.subscribe((event) => { console.log('route changed'); if(this.location.path() == '/1'){ this.title = 'Title 1'; } else if(this.location.path() == '/2'){ this.title = 'Title 2'; } }); I don't know if that make sense at all. I could change my route.ts paths to have something like { path: 'Title-1' }and just remove the - by doing .replace() but doing this will give me www.mysite.com/Title-1 but it doesn't look very friendly.