Hello I just got a fresh issue in Angular 14 with scrolling top, after navigation to other route via <router-outlet>
. I tried almost everything, below are my attempts:
appModule.ts
const routerOptions: ExtraOptions = {
useHash: false,
anchorScrolling: 'enabled',
scrollPositionRestoration: 'enabled'
// ...any other options you'd like to use
}
appComponent.ts
ngAfterViewChecked() {
window.scrollTo(0, 0);
}
onActivate(event: Event, outlet: HTMLElement) {
window.scroll(0,0);
console.log("Activate");
outlet.scrollTop = 0;
window.scroll({
top: 0,
left: 0,
behavior: 'smooth'
});
appComponent HTML:
<router-outlet (activate)="onActivate($event, outlet)" #outlet></router-outlet>
I will be grateful for each hint.