【发布时间】:2020-07-24 13:26:05
【问题描述】:
我有一个延迟加载功能模块 calendar.module 加载在app-routing.module 之类的
{
path: "calendars",
canActivate: [AuthGuard],
loadChildren: () =>
import("./calendars/calendar.module").then((m) => m.CalendarModule),
}
现在,我在calendar.module 中有一个CraftMapComponent
我想在没有像这样的 日历 前缀的情况下访问这个组件。
http://localhost:4200/teacher/craft-map
但我在calendar-routing.ts 中所能做的就是添加类似的路线
const routes: Routes = [
{ path: '', component: CalendarComponent, children: [
{ path: 'teacher/craft-map', component: CraftMapComponent }
]}
];
或
const routes: Routes = [
{ path: '', component: CalendarComponent },
{ path: 'teacher/craft-map', component: CraftMapComponent }
];
但两者都会解决
http://localhost:4200/calendar/teacher/craft-map
有什么方法可以让我省略日历前缀并仍然使用延迟加载模块?
【问题讨论】:
-
in path string 你让写你想要的
-
@TomaszVizaint:谢谢。我在问是否有任何方法可以覆盖该“前缀”
-
是的,这取决于您的 routerLink,因为如果在路径中您在 routerLink 中使用 {path: 'mylink', ....} 简单地写入 routerLink="/mylink",