Utilizing a UI service to control the styling of elements on my webpage is essential. The members of this service change with each route, determining how the header and page will look.
For example:
If the headerStyle
member of the service is set to dark, the dark header theme is applied for that specific route. If it is set to light, then the light theme takes over, and so forth.
The issue I encounter is when transitioning from 'route1' to 'route2', I must manually reset the service member for 'route2'. This becomes cumbersome as the new styles are only applicable to 2-3 pages, yet I still need to call the service on every page. Failure to do so means the values in the service remain unchanged, retaining the style from the previous route.
What I aim to achieve is this: once the route begins to change, all UI service styles should reset to default. Then, upon completion of the route change, if the new page has different values for the UI service, those should be applied; otherwise, render the page using default styles.
A similar question has been raised here:
How to detect a route change in Angular 2?
The challenge lies in the fact that the route change event fires after the transition is complete, ultimately overriding any code present on the page with default settings!