即時通訊使用多個路由器oulets來加載我的組件。 外部路由器插座用於加載大多數基本組件,例如登錄,home,404。 我使用嵌套的router-outlet加載主頁的子組件。該router-outlet嵌套在home.component中。使用嵌套路由器的角度4
home.component.html
<app-header></app-header>
<router-outlet name="homeRoute"></router-outlet>
<app-footer></app-footer>
app.module.ts
const appRoutes: Routes = [
{path: '', component: HomeComponent, children: [
{path: '', component: DashboardComponent, outlet: 'homeRouter'},
{path: 'user', component: UserComponent, outlet: 'homeRouter'},
{path: 'user/:id', component: UserdetailComponent, outlet: 'homeRouter'}
]},
{path: 'login', component: LoginformComponent},
{path: '**', component: NotfoundComponent}
];
HomeComponent和LoginformComponent需要從外路由器出口加載。 家庭組件包含名爲'homeRouter'的內部路由器插座,我想用它來加載主頁的子組件。 但內部路由器導航不會工作。我試圖使用router.navigate()方法和URL來訪問每個組件。但他們都沒有按預期工作。
有人可以告訴我這段代碼有什麼問題。我檢查並嘗試了幾個關於同一問題的問題,但沒有一個能正常工作。
下面是我嘗試了不同的組件
http://localhost:4200
dashboardComponet(這一個工程)http://localhost:4200/user
userComponent(不工作。路線notFoundComponent)http://localhost:4200/user/U001
userDetailComponent(doenst work.still航線的URL到notFoundComponent)
還有一個拼寫錯誤name =「homeRoute」outlet:'homeRouter' – DrMabuse