Angular Routing - disabling scrollPositionRestoration for certain routes or modules

Discussão em 'Angular' iniciado por Sajib Acharya, Março 21, 2025.

  1. I have an Angular app with quite a few lazy-loaded modules. I'm using scrollPositionRestoration: 'top' on my AppRoutingModule and everything is working as expected.

    // app-routing.module.ts

    ...
    @NgModule({
    imports: [
    RouterModule.forRoot(routes, {
    initialNavigation: 'enabled',
    scrollPositionRestoration: 'top',
    }),
    ],
    exports: [RouterModule],
    })
    export class AppRoutingModule { }


    However, I have one lazy-loaded module (FilterModule) which is basically a filter page for the products and based on the combination of filters selected, the routes change (adding / removing queryParams) which fires a route change event and the page is scrolled to top (as expected).

    But I would like to disable the scrollPositionRestoration "effect" particularly on this module and its routes. Is there an angular way to do this?

    Thanks!

    Continue reading...

Compartilhe esta Página