在Angular 7中使用side-nav在组件之间导航,可以通过以下步骤实现:
npm install @angular/material @angular/cdk @angular/animations
import { MatSidenavModule } from '@angular/material/sidenav';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [
MatSidenavModule,
BrowserAnimationsModule
],
...
})
export class AppModule { }
<mat-sidenav-container>
<mat-sidenav mode="side" opened>
<mat-nav-list>
<a mat-list-item routerLink="/home">Home</a>
<a mat-list-item routerLink="/about">About</a>
<a mat-list-item routerLink="/contact">Contact</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<router-outlet></router-outlet>
</mat-sidenav-content>
</mat-sidenav-container>
import { HomeComponent } from './home.component';
import { AboutComponent } from './about.component';
import { ContactComponent } from './contact.component';
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent },
{ path: 'contact', component: ContactComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
通过以上步骤,就可以在Angular 7中使用side-nav在组件之间进行导航了。side-nav组件提供了一个侧边栏导航菜单,可以通过点击菜单项来切换不同的组件内容。这种导航方式适用于需要在不同页面之间进行快速切换的场景。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云