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

200
Vistas
Prevent scroll to top before router navigate to another page when using angular 2 router resolve

I have a div tag with router link. When click div tag, it should navigate to another page. Also I am using router Resolve to fetch data before router activated.

{ path: 'conversation/:id', component: InboxDetailComponent, resolve: { conversation: InboxConversationResolver }}

This is how div tag is appearing.

<div class="list-group-item" *ngFor="let conversation of conversations; let j = index;" [routerLink]="['/app/inbox/detail',conversation.items[0].id]"></div>

Everything is working fine except one thing. When click div tag, page scrolls to top before navigate to another page. How to fix this?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I had the exactly same problem, but then i remembered I implemented the following in my app.component's constructor:

this.router.events.subscribe(
        () => window.scrollTo(0, 0)
    );

All I had to to was wait for the NavigationEnd event, instead of scrolling to the top on the first event that came through. So I implemented it like this:

this.router.events.subscribe((evt) => {
        if (!(evt instanceof NavigationEnd)) {
            return;
        }
        window.scrollTo(0, 0);
    });
about 4 years ago · Santiago Trujillo Denunciar
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