[英]Angular 2 router - aux route on the root url
I want to load aux route on the / URL but it does not work. 我想在/ URL上加载辅助路由,但是它不起作用。 For example, I want to load in my homepage the LoginComponent.
例如,我想在我的主页中加载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>
So now I am trying to access this URL and expecting to get the HomeComponent in the primary outlet and the LoginComponent in the auth outlet: 因此,现在我尝试访问此URL,并期望在主要出口处获得HomeComponent并在身份验证出口中获得LoginComponent:
http://localhost:4200/(auth:login) http:// localhost:4200 /(auth:登录)
But it only loads the LoginComponent and not the HomeComponent. 但是它仅加载LoginComponent而不加载HomeComponent。
You need to define redirect route: 您需要定义重定向路由:
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>
Or: 要么:
http://localhost/home(auth:login)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.