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?

+7


source to share


2 answers


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 .



+10


source


In ionic mode, we push the view screen from other views



But in angular mode it is a predefined route mapping, that if you go to that route i.e. app / login you will be redirected to the login route associated with loginComponent.

+1


source







All Articles