Skip to main content
2 of 3
added 2 characters in body
Abdul Rafay
  • 3.4k
  • 5
  • 27
  • 54

From Angular 6.1, you can now avoid the hassle and pass extraOptions to your RouterModule.forRoot() as a second parameter and can specify

scrollPositionRestoration: enabled

to tell Angular to scroll to top whenever the route changes.

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      scrollPositionRestoration: 'enabled',
    })
  ],
  ...

Angular Official Docs

Abdul Rafay
  • 3.4k
  • 5
  • 27
  • 54