角度路由与离子路由

Vah*_*afi 7 ionic2 angular2-routing angular

我是ionic2的新手.与纯角度路由相比,它的路由有些奇怪.在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
],
Run Code Online (Sandbox Code Playgroud)

我们传递一个常量类型Routes.

在Ionic(sidemenu starter)中,他们传递一个组件来forRoot运行.

import { MyApp } from './app.component';
imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
],
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Gre*_*dic 10

Ionic不支持URL路由,而是实现自定义导航解决方案 - NavController(由suraj链接).NavController维护着一堆页面 - 向前移动你将页面推送到堆栈this.nav.push(Page1);并向后移动你弹出它this.navCtrl.pop();.通过这种方式,您在浏览器中的URL始终相同,并且应用程序始终在主页上打开 - 这类似于移动应用程序行为.要启用对某个资源的直接访问(就像打开url myapp/items/1一样),您必须使用深层链接插件.

  • 你说的是哪个离子版本?在新的 Ionic (4+) 中它完全没问题。 (2认同)