我对角度路线有疑问,当我导航到子路线时,父路线会再次更新。
我将代码分离到2个主路由器出口:
显示登录页面
显示所有其他主页。
我具有以下结构:
app.module.ts
导入AppRoutingModule和MainModule
app.routing.module.ts
具有以下路线
const AppRouting: Routes = [
{ path: '', component: LoginComponent },
{ path: 'login', component: LoginComponent },
{ path: '**', component: PageNotFoundComponent }
];
app.component.html
<router-outlet></router-outlet>
main.module.ts
导入MainRoutingModule
main.routing.module.ts
const MainRouting: Routes = [
{
path: '',
component: MainComponent,
canActivateChild: [AuthGuardService],
children: [
{ path: '', redirectTo: 'welcome', pathMatch: 'prefix' },
{ path: 'welcome', component: WelcomeComponent },
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuardService],
data: { permission: { only: ['ALL_APP_ACTIONS', 'ALL_DASHBOARD_ACTIONS', 'DASHBOARD_VIEW'] } }
},
{ path: 'documents', component: DocumentsComponent , canActivate: [AuthGuardService],
data: { permission: { only: ['ALL_APP_ACTIONS', 'ALL_DOCUMENTS_ACTIONS', 'DOCUMENTS_VIEW'] } }
}
]
}
]
main.component.html
<div class="app-wrapper">
<lc-header></lc-header>
<div class="main {{leftMenuActive}}">
<lc-left-menu (doToggle)="doToggleSideBar()"></lc-left-menu>
<div class="app-main {{ currentRoutePath }}">
<div class="app-main-content">
<router-outlet></router-outlet>
</div>
</div>
</div>
<lc-footer></lc-footer>
</div>
因此,当我从欢迎页面移至仪表板时,父栏和左栏也会刷新。
有人可以帮忙吗?
谢谢!