2

I have set up a new application. When a route changes (normally) I want to scroll to the top of the page. I have setup my app-routing like this:

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      initialNavigation: "enabled",
      scrollPositionRestoration: "top",
      anchorScrolling: "enabled",
      scrollOffset: [0, 280], // [x, y] - adjust scroll offset
    }),
  ],
  exports: [RouterModule],
})
export class AppRoutingModule {}

But now I have a button that clears route parameters. I want the page to stay where it is, but it keeps scrolling to the top. I searched how to remove query parameters without activating the route change and found this:

Angular: How to update queryParams without changing route

So I did this:

public reset(e: MouseEvent): void {
  e.preventDefault();
  this.brandFilterService.reset();

  this.router.navigate([], {
    relativeTo: this.activatedRoute,
    queryParams: { query: null, id: null },
    queryParamsHandling: "merge",
  });
}

The problem is, it still scrolls to the top of the page. Is there anyway I can do this without it trying to scroll?

BSMP
  • 4,596
  • 8
  • 33
  • 44
r3plica
  • 13,017
  • 23
  • 128
  • 290
  • Does this answer your question? [Changing query params - page scrolls top, Angular](https://stackoverflow.com/questions/56663065/changing-query-params-page-scrolls-top-angular) – tommueller Aug 02 '21 at 12:39

0 Answers0