我已经搜索了半天,但我找不到任何有效的东西。
这些是我的路线。
app-routing.module.ts
const routes: Routes = [
{
path: '',
redirectTo: 'feature2',
pathMatch: 'full',
},
{
path: '',
canActivate: [MsalGuard],
loadChildren: (): Promise<FeaturesModule> => import('./features/features.module').then((m) => m.FeaturesModule),
},
{
path: 'auth',
component: MsalRedirectComponent,
},
{
path: '**',
component: ErrorPageComponent,
canActivate: [MsalGuard],
},
];
features-routing.module.ts
const routes: Routes = [
{
path: '',
component: FullLayoutComponent, // content with sidebar
canActivate: [AuthGuard],
children: [
{
path: 'feature1',
loadChildren: (): Promise<Feature1Module> => import('./feature1/feature1.module').then((m) => m.FeatureModule),
},
{
path: 'feature2',
loadChildren: (): Promise<Feature2Module> => import('./feature2/feature2.module').then((m) => m.FeatureModule),
},
],
},
{
path: '',
component: ContentLayoutComponent, // content without sidebar
children: [
{
path: 'feature3',
loadChildren: (): Promise<Feature3Module> => import('./feature3/feature3.module').then((m) => m.FeatureModule),
},
],
},
app.component.ts
有一个router-outlet
。full-layout-component.ts
和 也是如此content-layout-component.ts
。当我尝试从feature3
(内部feature3
)导航到feature2
没有任何反应router.navigate('feature2')
时。检查跟踪后,我有这个:
Router Event: NavigationStart
NavigationStart(id: 3, url: '/feature2')
NavigationStart{id: 3, url: "/feature2", navigationTrigger: "imperative", restoredState: null}id: 3navigationTrigger: "imperative"restoredState: nullurl: "/feature2"__proto__: RouterEvent
Router Event: RoutesRecognized
RoutesRecognized(id: 3, url: '/feature2', urlAfterRedirects: '/feature2', state: Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'feature2', path:'feature2') { Route(url:'', path:'') { Route(url:'', path:'') } } } } } )
RoutesRecognized{id: 3, url: "/feature2", urlAfterRedirects: "/feature2", state: RouterStateSnapshot}
Router Event: GuardsCheckStart
GuardsCheckStart(id: 3, url: '/feature2', urlAfterRedirects: '/feature2', state: Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'', path:'') { Route(url:'feature2', path:'feature2') { Route(url:'', path:'') { Route(url:'', path:'') } } } } } )
GuardsCheckStart{id: 3, url: "/feature2", urlAfterRedirects: "/feature2", state: RouterStateSnapshot}
Event: ChildActivationStart
ChildActivationStart(path: '')
ChildActivationStart{snapshot: ActivatedRouteSnapshot}
Router Event: ActivationStart
ActivationStart(path: '')
ActivationStart{snapshot: ActivatedRouteSnapshot}
如果我手动导航到feature2
它按预期工作。我想我错过了一些东西,但看不到什么。我怎样才能得到这个工作?