javascript - Angular 5 Scroll to top on every Route click - Stack Overflow

PHOTO EMBED

Wed Jun 22 2022 13:16:39 GMT+0000 (UTC)

Saved by @saranraj #angular

<router-outlet (activate)="onActivate($event)"></router-outlet>

onActivate(event) {
   // window.scroll(0,0);

   window.scroll({ 
           top: 0, 
           left: 0, 
           behavior: 'smooth' 
    });

    //or document.body.scrollTop = 0;
    //or document.querySelector('body').scrollTo(0,0)
    ...
}
content_copyCOPY

https://stackoverflow.com/questions/48048299/angular-5-scroll-to-top-on-every-route-click