angular - Angular 路由:主页 URL 应为 http://localhost:4200/
问题描述
我已经在我的项目中完成了 URL 路由。当我重定向到主页时,URL 变为 http://localhost:4200/home。
我希望我的主页 URL 是 http://localhost:4200/ 而不是 http://localhost:4200/home
我的 app.routing.ts 文件:
const routes: Routes =
[
{
path: '',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: '',
component: LayoutComponent,
children: [
{
path: 'home',
loadChildren: './home/home.module#HomeModule'
}
]
}
];
下面是 home.routing.ts 文件:
const routes: Routes = [
{
path: '',
component: HomeComponent
}
];
任何帮助将不胜感激,谢谢。
解决方案
您可以使用以下方式实现相同的目的
app.routing.ts
const routes: Routes = [
{
path: '',
loadChildren:
'./home/home.module#HomeModule'
},
{
path: '',
loadChildren:'./another/another.module#AnotherModule'
}
];
并在 Home 模块路由器中
const routes: Routes = [
{
path: '',
component: LayoutComponent,
children: [
{
path: '',
component: HomeComponent,
},
{
path: 'other',
component: otherComponent,
},
]
}
];