我相信你的路线是错误的。
HomeComponent
应该是
AppComponent
s的孩子,对吗?
我认为应该是这样的:
const appRoutes: Routes = [
{
path: 'login',
component: LoginComponent
},
{
path: '',
component: AppComponent,
children: [
{
path: '',
component: HomeComponent,
canActivate: [AuthGuard],
pathMatch: 'full'
},
// otherwise redirect to home
{ path: '**', redirectTo: '' }
]
}
];
或者像这样:
const appRoutes: Routes = [
{
path: '',
component: AppComponent,
children: [
{
path: '',
component: HomeComponent,
canActivate: [AuthGuard],
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
// otherwise redirect to home
{ path: '**', redirectTo: '' }
]
}
];
你的
<router-outlet></router-outlet>
应该是哪个组件的出口?