How to transfer data between Ionic Pages using router examples

Example 1: passing data from one page to another in ionic 4

import { Component } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router';
import { DataService } from '../services/data.service';
 
@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
 
  user = {
    name: 'Simon Grimm',
    website: 'www.ionicacademy.com',
    address: {
      zip: 48149,
      city: 'Muenster',
      country: 'DE'
    },
    interests: [
      'Ionic', 'Angular', 'YouTube', 'Sports'
    ]
  };
 
  constructor(private router: Router, private dataService: DataService) { }
 
  openDetailsWithState() {
    let navigationExtras: NavigationExtras = {
      state: {
        user: this.user
      }
    };
    this.router.navigate(['details'], navigationExtras);
  }
}

Example 2: passing data from one page to another in ionic 4

import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { DataService } from '../services/data.service';
 
@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
 
  user = {
    name: 'Simon Grimm',
    website: 'www.ionicacademy.com',
    address: {
      zip: 48149,
      city: 'Muenster',
      country: 'DE'
    },
    interests: [
      'Ionic', 'Angular', 'YouTube', 'Sports'
    ]
  };
 
  constructor(private router: Router, private dataService: DataService) { }
 
  openDetailsWithService() {
    this.dataService.setData(42, this.user);
    this.router.navigateByUrl('/details/42');
  }
}

Example 3: passing data from one page to another in ionic 4

<ion-header>
  <ion-toolbar>
    <ion-title>
      Ionic Data Navigation
    </ion-title>
  </ion-toolbar>
</ion-header>
 
<ion-content padding>
  <ion-button expand="full" (click)="openDetailsWithQueryParams()">
    Open with Query Params
  </ion-button>
 
  <ion-button expand="full" (click)="openDetailsWithService()">
    Open with Service
  </ion-button>
 
  <ion-button expand="full" (click)="openDetailsWithState()">
    Open with State
  </ion-button>
</ion-content>

Example 4: passing data from one page to another in ionic 4

import { DataResolverService } from './resolver/data-resolver.service';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
 
const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', loadChildren: './home/home.module#HomePageModule' },
  { path: 'details', loadChildren: './details/details.module#DetailsPageModule' },
  {
    path: 'details/:id',
    resolve: {
      special: DataResolverService
    },
    loadChildren: './details/details.module#DetailsPageModule'
  }
];
 
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }