Now, to complete the final step and implement those routes in our app-routing.module.ts file, they would look like this:
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', loadChildren: './pages/home/home.module#HomeModule' },
{ path: 'products', loadChildren: './pages/products/products.module#ProductsModule'},
{ path: 'products/:id', loadChildren: './pages/product-detail/product-detail.module#ProductDetailModule' },
{ path: 'products/categories', loadChildren: './pages/product-categories/product-categories.
{ path: 'support', loadChildren: './pages/support/support.module#SupportModule' }
];
setRoot in html page
<ion-button href="/support" routerDirection="root">
or in class
this.navCtrl.navigateRoot('/support');
Push
<ion-button href="/products/12" routerDirection="forward">
or
this.navCtrl.navigateForward('/products/12');
Pop
<ion-button href="/products" routerDirection="backward">
or
<ion-back-button defaultHref="/products"></ion-back-button>
you can also navigate backwards programatically:
this.navCtrl.navigateBack('/products');
p/s: https://www.joshmorony.com/converting-ionic-3-push-pop-navigation-to-angular-routing-in-ionic-4/
NavController
? – Cockalorumimport { MenuController, NavController } from '../../../../node_modules/@ionic/angular';
– Basieimport { MenuController, NavController } from 'ionic-angular';
. What error/s are you getting? – Cockalorumimport { MenuController, NavController } from 'ionic-angular';
isn't work for me. Because, it can't find ionic-angular. I also searched Ionic 4 documentation. But, this is not clear. @JosephWebber – BasieNavController
, onlyNav
. Try changingNavController
toNav
and see if that works. – Cockalorumthis.navCtrl.goForward('/list');
it's work for Ionic 4! Ionic 4 suggests to use angular routing. But, now the problem is there is no back button in navbar when I go to the second page! – Basieimport { MenuController, NavController } from '@ionic/angular';
. About back button you need to add it yourself now : github.com/ionic-team/ionic/blob/master/angular/… – Campstool