我正在创建带有链接的侧边栏。我有3个组件,侧边栏组件链接了2个工具栏组件,因此每次隐藏侧边栏时都可以使用菜单按钮。
这在我的侧边栏组件上。
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'side' : 'side'"
[opened]="(isHandset$ | async) === false">
<mat-toolbar>Cust_Corp</mat-toolbar>
<div class="dashboard">
<div class="container">
<p><a routerLink="/cust-toolnav">Home</a></p>
<p><a routerLink="/cust-regform">Create a customer</a></p>
<p><a href="#">Display a customer</a></p>
</div>
<router-outlet></router-outlet>
</div>
</mat-sidenav>
<mat-sidenav-content>
<app-cust-toolnav [title]="title" [burgerMenu]="isHandset$ | async" (burgerClick)="drawer.toggle()"></app-cust-toolnav>
</mat-sidenav-content>
<mat-sidenav-content>
<app-cust-regform [title]="title" [burgerMenu]="isHandset$ | async" (burgerClick)="drawer.toggle()"></app-cust-regform>
</mat-sidenav-content>
</mat-sidenav-container>
我的第二个工具栏有一个。每次单击链接时,URL都会更改,但工具栏主体不会更改。
<p><a routerLink="/cust-toolnav">Home</a></p>
<p><a routerLink="/cust-regform">Create a customer</a></p>
我有检查应用程序路由模块以包含
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CustToolnavComponent } from './cust-toolnav/cust-toolnav.component';
import { CustRegformComponent } from './cust-regform/cust-regform.component';
const routes: Routes = [
{ path: '', redirectTo: 'cust-toolnav', pathMatch: 'full' }, <-- I tried removing / and adding /.
{ path: 'cust-toolnav', component: CustToolnavComponent },
{ path: 'cust-regform', component: CustRegformComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
那是因为您错误地实施了sidenav。它应该只有1 <mat-sidenav-content>
,并将路由器出口放置在<mat-sidenav-content>