我有以下应用程序:
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
路由有效而重定向无效?
答案 0 :(得分:-1)
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),
],