ionic router pass data code example
Example 1: 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 { }
Example 2: passing data from one page to another in ionic 4
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/"></ion-back-button>
</ion-buttons>
<ion-title>Details</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-card *ngIf="data">
<ion-card-header>
<ion-card-title>
{{ data.name }}
</ion-card-title>
<ion-card-subtitle>
{{ data.website }}
</ion-card-subtitle>
</ion-card-header>
<ion-card-content>
<ion-item *ngFor="let i of data.interests">
{{ i }}
</ion-item>
</ion-card-content>
</ion-card>
</ion-content>