简体   繁体   中英

Prevent page jump on Router.Navigate

On click of the following link the current page jumps to the top before navigating to the other page.

<a href="javascript:void(0);" (click)="goToTicket(x.refNo, $event)">{{x.ticketTitle}}</a>

component.ts

  goToTicket(refNo, e) {

    e.preventDefault();
    this.router.navigate(['/ticket/ticket-details'], { queryParams: { id: refNo } });
  }

How do I prevent the page jump here?

You should remove this code

href="javascript:void(0);" 

or use

<a [routerLink]="['/ticket/ticket-details']" [queryParams]="{ id: x.refNo }">{{x.ticketTitle}}</a>

You can use scrollPositionRestoration

you just need to disable this in the router configuration like this

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

Stackblitz example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM