繁体   English   中英

带有loadChildren的角默认路由redirectTo

[英]Angular default route redirectTo with loadChildren

我有以下应用程序:

const routes: Routes = [
  { path: '', redirectTo: 'demo', pathMatch: 'full' },
  { path: 'demo',  loadChildren: () => ChildModule },
];

imports: [
    RouterModule.forRoot(routes),
],

它在loadChildren使用此模块

const routes: Routes = [
  {
    path: '',  component: DemoComponent,
    children: [
      { path: 'some', component: SomeComponent },
      { path: 'other', component: OtherComponent },
    ],
  },
];

imports: [
    RouterModule.forChild(routes),
],

如果我启动应用程序,则定义了两条路线:

http://localhost:4200/demo/some

http://localhost:4200/demo/other

同样有效的是:

http://localhost:4200/some

http://localhost:4200/other

当我导航到http://localhost:4200/它没有重定向到http://localhost:4200/demo

那么为什么路由/some/other起作用而重定向不起作用?

const routes: Routes = [
  { path: '', redirectTo: 'demo', pathMatch: 'full' },
  { path: 'someother',  loadChildren: () => ChildModule },
];

imports: [
    RouterModule.forRoot(routes),
],

=======================================================

const routes: Routes = [
  {
    path: "", redirectTo: "some", pathMatch: "full"
    },
    {
    path: "some",
    component: SomeComponent
    },
    {
    path: "other",
    component: OtherComponent
    }    

];

imports: [
    RouterModule.forChild(routes),
],

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM