Angular routing vs ionic routing
I am new to ionic2. There is something weird about this routing compared to pure angular routing. In angular:
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'hero/:id', component: HeroDetailComponent },
{
path: 'heroes',
component: HeroListComponent,
data: { title: 'Heroes List' }
},
{ path: '',
redirectTo: '/heroes',
pathMatch: 'full'
},
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
// other imports here
],
We are passing a constant with a type Routes
.
In Ionic ( sidemenu starter) they pass a component to a function forRoot
.
import { MyApp } from './app.component';
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
Any ideas?
source to share
Ionic doesn't support url routes, instead it implements a custom navigation solution - NavController (linked to suraj). The NavController maintains a stack of pages - moving forward you push the page onto the stack this.nav.push(Page1);
and move backward you push it this.navCtrl.pop();
. So your url in the browser is always the same and the app always opens on the homepage, which is similar to the behavior of a mobile app. To enable direct access to a specific resource (since you will open url myapp / items / 1), you must use the deep linking plugin .
source to share