My page has various components stacked one after the other, such as:
<about></about>
<contact></contact>
I am utilizing the ng2-page-scroll to smoothly scroll to a particular section when a navigation link is clicked. However, I am facing an issue with scrolling to the desired section upon application initialization.
When a user first opens the page with '/contact' in the route, I want it to automatically scroll down to the contact section instead of staying at the top.
In my implementation, I have included the following code snippet:
if(this.router.url != '/') {
let pageScrollInstance: PageScrollInstance = PageScrollInstance.simpleInstance(this.document, '#'+this.router.url.substring(1));
this.pageScrollService.start(pageScrollInstance);
}
This code is placed inside the constructor, but it seems to execute before the router sets the route on 'router.url'.
I tried using 'window.location.href.split("/").pop()' to obtain the address before the router is set, but this triggers before the components are fully rendered, resulting in scrolling to the wrong position.
Is there a hook available that triggers once the entire app routing is set and everything is rendered?