我想在/ URL上加载辅助路由,但是它不起作用。例如,我想在我的主页中加载LoginComponent。
const routes : Routes = [
{
path: '',
pathMatch: 'full',
component: HomeComponent
},
{
path: 'login',
outlet: 'auth',
component: LoginComponent
}
];
<router-outlet></router-outlet>
<router-outlet name="auth"></router-outlet>
因此,现在我尝试访问此URL,并期望在主要出口处获得HomeComponent并在身份验证出口中获得LoginComponent:
http:// localhost:4200 /(auth:登录)
但是它仅加载LoginComponent而不加载HomeComponent。
您需要定义重定向路由:
const routes : Routes = [
{
path: '',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: 'home',
component: HomeComponent
},
{
path: 'login',
outlet: 'auth',
component: LoginComponent
}
];
<a [routerLink]="[{ outlets: { 'auth': ['login'] } }]">Sign in</a>
或者:
http://localhost/home(auth:login)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句