Angular’s new router title feature

How to apply Angular's latest router feature to dramatically simplify your code

Kevin Kreuzer
4 min readJun 7, 2022

When building Angular apps it's good practice to update the title of the tab on every successful navigation.

Adding a page title improves accessibility and user experience. So far, you had to build this feature yourself, however, in Angular 14, this feature is provided by the framework. Let’s take a look.

What we had to do so far

To change the page title after successful navigation we had to provide the page title as a data property in our route configuration.

Provide the page title as route data

We then manually had to implement some logic to access the provided title attribute and update the tab's title.

Manual implementation to change the tab title

We had to listen to all NavigationEnd events and then map this event into the title of the tab. We then finally used a titleService which we inject as Title from @angular/platform-browser to set the title.

--

--

Kevin Kreuzer

Passionate freelance frontend engineer. ❤️ Always eager to learn, share and expand knowledge.