此演示有 2 個插座(定義在app.module.ts:
<router-outlet></router-outlet>
<router-outlet name="b"></router-outlet>
這些路線:
const routes: Routes = [
{ path: 'a', component: HelloComponent },
{ path: 'b', outlet: 'b', component: HelloComponent },
];
這些按鈕用于測驗路線( In app.component.html)。
<button routerLink="a">router link a</button>
<button routerLink="b">router link b</button>
路由一個作品。但是,當單擊路由 b 時,會創建此錯誤:
ERROR
Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'b'
Error: Cannot match any routes.
想法?
uj5u.com熱心網友回復:
routerLink默認情況下始終使用主插座,您必須指定插座才能導航到它。在你的情況下:
<a [routerLink]="[{ outlets: { 'b': ['b'] } }]">Component Aux</a>
該錯誤是有道理的,因為沒有b為主要出口定義命名的路由。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/529106.html
