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

296
Views
How to update/refresh an Angular Router 'state'?

I am trying to pass data from one page to another with Angular routing. It works perfectly fine when entering the "next" page for the first time. However, when going back to the home page and pressing another item the state of the Router will not be updated. It will continue to show values from the first time an item was clicked.

Anyone an idea how to make that work?

I already tried several things e.g. resetting all values "manually":

  pageBack() {
    this.router.navigate(['tabs/homepage'], { 
      state: { 'space': undefined }
    });
    this.space = {};
    this.userId = '';
    this.spaceId = '';
    this.spaceName = '';
  }

Here is the code:

home.page.html

<div *ngIf="spaces">
  <ion-item-sliding *ngFor="let space of spaces | async;">
    <ion-item (click)="openspacedetailsPage(space)" detail>
      <ion-icon name="ellipse-outline" start></ion-icon>
      <ion-label>
        &nbsp; {{ space.spaceName }}
      </ion-label>
    </ion-item>
  </ion-item-sliding>
</div>

home.page.ts

  openspacedetailsPage(space) {
    this.router.navigate(['tabs/space-details'], {
      state: { 'space': space }
    });
  }

space-details.page.html

<ion-header>
  <ion-toolbar>
    <ion-buttons slot="start">
      <ion-back-button defaultHref="tabs/activities" (click)="pageBack()"></ion-back-button>
    </ion-buttons>
    <ion-title>{{ spaceName }}</ion-title>
  </ion-toolbar>
</ion-header>

space-details.page.ts

  pageBack() {
    this.router.navigate(['tabs/homepage'], { 
      state: { 'space': undefined }
    });
    this.space = {};
    this.userId = '';
    this.spaceId = '';
    this.spaceName = '';
  }

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

In this case you need to use Angular EventEmitter.

You can check this answer. What is the proper use of an EventEmitter?

over 4 years ago · Santiago Trujillo Report

0

I solved with a slightly different approach using a data service to pass values between pages: How to pass Objects between pages in Angular?

over 4 years ago · Santiago Trujillo Report
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!