I’m not sure if it’s to late but for everyone who’s looking for an answer to this:
With Ionic 4 you have two ways of navigate through pages.
Using the Angular Router (web-like) or the NavController (mobile-like) or a mix of both.
If we have Page1
and Page2
using just the Angular Router we could do something like
1.- Register your route on the module router
@NgModule({
imports: [
IonicModule,
CommonModule,
FormsModule,
RouterModule.forChild([{ path: 'page1', component: Page1 }, { path: 'page2', component: Page2 }])
],
declarations: [Page1, Page2]
})
2.- On the template we can use
From Page 1
<ion-item routerLink="/page2">To Page2</ion-item>
Notice that you can use routerLink
on any HTML tag. Including not Ionic web components.
This navigation will push Page2 into the current stack (Stack === Root component which have an )
The other way, is using the Ionic NavController. This is really useful when you don’t know to which page are you going and you just want to pop a page.
You can use this programatically like @joshmorony suggested.
If you use
<ion-item href="/page2" routerDirection="forward"></ion-item>
On your template. You will lose state on the app on the navigation. This kind of navigation triggers a navigation like SSR. This one can’t be used on any web component.