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?