【发布时间】:2017-12-23 04:52:40
【问题描述】:
我正在使用带有子节点的路由,这些子节点应该加载到单独的插座中。 所有组件都直接放在 /app 文件夹中。
app.router.ts:
export const router: Routes = [
{ path:'dashboard', canActivate:[AuthguardGuard], component: DashboardComponent },
{ path:'', component: LoginComponent },
{
path: 'dashboard', component: DashboardComponent,
children: [
{ path:'features', component: FeaturesComponent, outlet:
{ path:'signup', component: SignupComponent, outlet: 'content' },
{ path:'more', component: MoreComponent, outlet: 'content',
{ path: '**', component: PageNotFoundComponent }
]
}
];
dashboard.component.html:
<a [routerLink]="['./']">Overview</a>
<a [routerLink]="['features']">Features</a>
<a [routerLink]="['details']">How To</a>
<a [routerLink]="['more']">SignUp</a>
<a [routerLink]="['signup']">SignUp</a>
当在http.//localhsot:4200 下加载应用程序时,我首先从一个登录组件/页面(默认加载在未命名的路由器插座中)开始检查用户并通过。之后它进入仪表板组件/页面(使用 AuthguardGuard)。网址为:http://localhost:4200/dashboard
从仪表板页面我希望能够导航到其他页面/组件,它们应该加载到插座中:“内容”
app.component.ts:
<main class="mdl-layout__content">
<div class="mdl-layout__tab-panel is-active" id="overview">
<router-outlet></router-outlet>
<router-outlet name="content"></router-outlet>
</div>
</main>
我一直在尝试在平台上找到的一些建议,但都没有帮助。例如。:
<a [routerLink]="['signup', {outlets: {content: 'signup'}}]">SignUp</a>
<a [routerLink]="['../signup']">SignUp</a>
但它不起作用......不同的错误,如:
Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'signup'
任何想法我做错了什么或者我应该改变或添加什么?
【问题讨论】:
-
我的回答解决了你的问题吗?
-
很遗憾不是.. 同样的错误:
Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'signup' -
你有没有找到任何解决方法,因为我遇到了同样的问题。但对我来说 ['/dashboard',{outlets: {content:'signup'}}] 有效。但它创建了一个我无法使用的 URL。
-
@PraveenRawat:是的,现在工作正常。您能否发布您无法使用的生成的 URL。这会很有帮助。