angular2延迟加载模块路由

时间:2017-03-28 17:37:24

标签: angular routes

我在主路线模块上得到了这个:

 { 
    path: 'alpha/aaa', 
    loadChildren: 'app/connection/connection.module#ConnectionModule'
  },

  { 
    path: 'num/123', 
    loadChildren: 'app/connection/connection.module#ConnectionModule'
  },

  { 
    path: 'rand/a2b1', 
    loadChildren: 'app/connection/connection.module#ConnectionModule'
  },

路线不同但它们在一个模块中,因为它们具有相同的模板和功能。

我的问题是,如果那些是我需要的确切路径,我将如何在子模块的路径中映射上面定义的路径?所以我尝试了以下但没有工作:

const routes: Routes = [
  { path: 'alpha/aaa', pathMatch:'full', component: Component1 },
  { path: 'num/123', pathMatch:'full', component: Component2 },
  { path: 'rand/a2b1', pathMatch:'full', component: Component3 }
];

1 个答案:

答案 0 :(得分:1)

不幸的是,这是不可能做到的,但是如果你改变你的路线并为整个模块提供一个共同的路线,你可以实现类似的东西。即:

{ 
    path: 'connection', 
    loadChildren: 'app/connection/connection.module#ConnectionModule'
}

然后就像你现在一样

const routes: Routes = [
  { path: 'alpha/aaa', component: Component1 },
  { path: 'num/123', component: Component2 },
  { path: 'rand/a2b1', component: Component3 }
];

然后你会像

那样访问它们
/connection/alpha/aaa 
/connection/num/123
/connection/rand/a2b1
相关问题