我有一些路由模块,其主路径设置为:/canvas
const canvasRoutes: Routes = [
{
path: "canvas", component: CanvasComponent
}
];
@NgModule({
imports: [
RouterModule.forChild(canvasRoutes)
],
exports: [
RouterModule
],
declarations: [],
providers: []
})
export class CanvasRoutingModule {
}
在应用程序路由模块中,我希望每次访问根路径时重定向路径设置为
/canvas
。当前配置如下:const appRoutes: Routes = [
{
path: "", redirectTo: "/canvas", pathMatch: "full"
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [
RouterModule
],
declarations: [],
providers: []
})
export class AppRoutingModule {
}
它可以正常工作,并且访问 http://localhost:4201
会被重定向到 http://localhost:4201/canvas
。
然而,我不想在重定向后的URL中附加 /canvas
路径。如何实现这一点?例如,我是否可以像在 router.navigate(... {skipLocationChange: true})
中使用的那样应用 skipLocationChange
参数来进行重定向?
path: "", component: CanvasComponent
或path: "", component: XXX, children: [{path: "", component: CanvasComponent}]
不已经足够了吗? - ulubeynrouterLink='/canvas'
将其路由到画布组件。如果我将其更改为routerLink=''
,该语句将变得不清晰。 - Kamil Chaber