1//inside the app.component.html add (activate):
2<router-outlet (activate)="onActivate($event)"></router-outlet>
3
4//inside app.component.ts, add inside the class of the component:
5export class AppComponent {
6
7 onActivate(event) {
8 window.scroll(0,0);
9 //or document.body.scrollTop = 0;
10 //or document.querySelector('body').scrollTo(0,0)
11
12}
13}
14
1RouterModule.forRoot(appRoutes, { scrollPositionRestoration: 'enabled' })
2
1import { Component, OnInit } from '@angular/core';
2import { Router, NavigationEnd } from '@angular/router';
3
4@Component({
5 selector: 'my-app',
6 template: '<ng-content></ng-content>',
7})
8export class MyAppComponent implements OnInit {
9 constructor(private router: Router) { }
10
11 ngOnInit() {
12 this.router.events.subscribe((evt) => {
13 if (!(evt instanceof NavigationEnd)) {
14 return;
15 }
16 window.scrollTo(0, 0)
17 });
18 }
19}