I am new to ionic.
I want to pass the parameter from one page to the tabs page.
Basically it’s a place list. On click of the item, I want to pass place_id to place tab pages.
There are 3 tabs: Place Detail, Member List, Events.
I want to pass place_id to all pages.
On click of an item if I pass a parameter to the tabs page it won’t work. But without parameter, it works perfectly. It goes to the tabs page.
app-routing.module.ts
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: 'tab',
loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
},
{
path: 'member-detail',
loadChildren: () => import('./member-detail/member-detail.module').then( m => m.MemberDetailPageModule)
},
{
path: 'member-detail/:userId',
loadChildren: () => import('./member-detail/member-detail.module').then( m => m.MemberDetailPageModule)
},
{
path: '',
loadChildren: () => import('./login/login.module').then( m => m.LoginPageModule)
},
{
path: 'register',
loadChildren: () => import('./register/register.module').then( m => m.RegisterPageModule)
},
{
path: 'forgot-password',
loadChildren: () => import('./forgot-password/forgot-password.module').then( m => m.ForgotPasswordPageModule)
},
{
path: 'otp',
loadChildren: () => import('./otp/otp.module').then( m => m.OtpPageModule)
},
{
path: 'edit-profile',
loadChildren: () => import('./edit-profile/edit-profile.module').then( m => m.EditProfilePageModule)
},
{
path: 'forgot-change-password',
loadChildren: () => import('./forgot-change-password/forgot-change-password.module').then( m => m.ForgotChangePasswordPageModule)
},
{
path: 'forgot-change-password/:contact',
loadChildren: () => import('./forgot-change-password/forgot-change-password.module').then( m => m.ForgotChangePasswordPageModule)
},
{
path: 'member-list',
loadChildren: () => import('./member-list/member-list.module').then( m => m.MemberListPageModule)
},
{
path: 'places',
loadChildren: () => import('./places/places.module').then( m => m.PlacesPageModule)
},
// {
// path: 'place-tab',
// loadChildren: () => import('./place-tab/place-tab.module').then( m => m.PlaceTabPageModule)
// },
{
path: 'place-tab/:placeId',
loadChildren: () => import('./place-tab/place-tab.module').then( m => m.PlaceTabPageModule)
},
{
path: '',
loadChildren: () => import('./place-tab/place-tab.module').then( m => m.PlaceTabPageModule)
},
{
path: '',
loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule {}
places.page.ts
placeDetail(placeId: string) {
console.log(placeId);
this.router.navigate(['/place-tab/', placeId]);
// this.router.navigateByUrl('/place-tab');
}
place-tab.page.ts
export class PlaceTabPage {
placeId: any;
constructor(private activatedRoute: ActivatedRoute) {
this.activatedRoute.params.subscribe(params => {
this.placeId = params['placeId'];
});
console.log(this.placeId);
}
}
place-tab-routing.module.ts
const routes: Routes = [
{
path: 'place-tab',
component: PlaceTabPage,
children: [
{
path: 'place-detail',
children: [
{
path: '',
loadChildren: () =>
import('../place-detail/place-detail.module').then(m => m.PlaceDetailPageModule)
}
]
},
{
path: 'place-member',
children: [
{
path: '',
loadChildren: () =>
import('../place-member/place-member.module').then(m => m.PlaceMemberPageModule)
}
]
},
{
path: 'place-event',
children: [
{
path: '',
loadChildren: () =>
import('../place-event/place-event.module').then(m => m.PlaceEventPageModule)
}
]
},
{
path: '',
redirectTo: '/place-tab/place-detail',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/place-tab/place-detail',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class PlaceTabPageRoutingModule { }