Search code examples
angularangular-router

Scrolling issue on route change


I have a store component with a list of products https://localhost:4200/shop and a component with product details https://localhost:4200/shop/10 (opens when you click on a specific product in the store component). So, why if I scroll down the page of the store component, does the page with details open with a downward scroll after clicking on a product?


Solution

  • In your app routing module, use scrollPositionRestoration like this

    RouterModule.forRoot(routes, {
        anchorScrolling: 'enabled',
        scrollPositionRestoration: 'enabled'
      })
    

    Reference: Angular Documentation