在 app.component.html 我們有一個 <router-outlet> 它將動態加載其他模塊和組件和視圖。
但是如果我們有第二個組件(在不同的模塊中匯入)有它自己的 < router-outlet >
例如,角度如何區分現有的 2 個路由器插座,角度如何知道
“router1”(包含路徑:“/url-1”路徑:“/url-2”)在 app.component.html 中加載。并且“router2”(包含路徑:“/url-3”路徑:“/url-4”)被加載到 secondComp.component.html
當 app.componen.html 和 secondComp.component.html 都有這個標簽時,特別是 < router-outlet >
角度如何知道 x 組件需要使用/加載哪個路由器定義。
僅用于學習目的
uj5u.com熱心網友回復:
路由的 Angular 概念在 app.component.html 中定義,全域路由意味著應用程式默認 UI 或父路由是從中渲染的。&在我們的路由檔案中,我們區分了路由的父路徑和子路徑的路徑,例如:
app.component.html
<div>
<router-outlet></router-outlet>
</div>
app.module.ts
在進口部分
RouterModule.forRoot([
{ path: '', component: LoginComponent, pathMatch: 'full' },
{ path: 'Login', component: LoginComponent, canActivate: [AuthGuardService] },
{ path: 'Home', loadChildren: () => import('./librarymanagement/librarymanagement.module').then(m => m.LibraryManagementModule) },
])
因此,所有父級路由都在父級 [Login, Home] 渲染,因此這兩個路由都視為父路由。
現在在 Home 路由加載功能模塊中稱為LibraryManagementModule.
const routes: Routes = [
{
path: '', component: LibraryManagementComponent,
children: [{ path: 'Dashboard', component: DashbordComponent, canActivate: [AuthGuardService] },
{ path: 'country', component: CountryComponent, canActivate: [AuthGuardService] },
}
現在子路由在 Home 中加載其名為 [Dashboard,country] 的子路由route。作為 的孩子RouterModule。
RouterModule.forChild(routes)
因此,所有路由都被視為樹來指示要呼叫的特定識別符號。內部LibraryManagementModule引導組件LibraryManagementComponent包含
圖書館管理.component.html
<div>
<router-outlet></router-outlet>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/532563.html
標籤:有角度的路由器插座
