Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

438
Views
Scroll to top on route change not working Angular 13

I am facing a weird problem. I am trying to implement scroll to top functionality on route change in Angular and I have tried various methods. For all the methods the scroll to top functionality works perfectly fine when testing on my laptop but they act weirdly when opened on mobile/iPad.

For some links it does scroll to the top as expected but for some other links it just loads the component without scrolling to the top. What's weird is that it happens only on my mobile/iPad. On laptop it works completely fine.

I had implemented the following solutions for this scroll to top functionality:

Method 1:
I implemented a scrollToTop() function which I was calling on click event on the anchor tags with the routerLink.

scrollToTop() {
   window.scroll(0,0);
}

And my links looked like this:

<li class="nav-item" routerLinkActive="active">
  <a class="nav-link" routerLink="about" (click)="scrollToTop()">About Us</a>
</li>

Method 2:
I added the scrollPositionRestoration: 'enabled' option in the app routing module.

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

Both the above methods are working on laptop but not on mobile devices. In case it's of any importance, I am using lazy-loading in my application and AOT during building the application. Am I missing something?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!