Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
Ionic 6 and Angular navigates to route which is already in history

I am using Ionic 6 and Angular 12 and I have couple pages in the app flow. I wen to page_4 and when I checked my DOM structure it looks like:

<ion-router-outlet>
    <page_1></page_1>
    <page_2></page_2>
    <page_3></page_3>
    <page_4></page_4>
</ion-router-outlet>

After page_4 I want to navigate to new page_2 and send some data via state object:

this.router.navigateByUrl('/page_2', { state: {dataHasChanged: true} });

I expected:

  1. Ionic will create again new <page_2></page_2> tag into DOM bellow <page_4></page_4>

  2. I can retrieve state data like I usually do:

    this.router.getCurrentNavigation().extras?.state?.dataHasChanged
    

But result is different:

  1. App back to the previous <page_2></page_2> and my DOM structure looks like:

    <ion-router-outlet>
        <page_1></page_1>
        <page_2></page_2>
    </ion-router-outlet>
    
  2. this.router.getCurrentNavigation().extras is null and cannot see my data here. But I can see state data into windows.history.state object

Can someone please explain me why this happened or at least refer me to some valuable documentation ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you enter a page that has already been loaded, it will not load again, or at least, not always. You can celar or update the content of the page inside ionViewWillEnter.

check this

add it in your page.ts

ionViewWillEnter() {
    ...
}

To solve the problem of navigation extras empty you can share data with a Service like this. It's not the cleanest way but it works

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class DataShareService {

  private __dataDict = {};

  setData(key: string, data: any) {
    this.__dataDict[key] = data;
  }
  getData(key: string) {
    return this.__dataDict[key];
  }

}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda