Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

442
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda