作者:胸膛舒畅_736 | 来源:互联网 | 2023-10-11 14:20
Angular11andng-zorro-antd11创建一个带路由的ng项目ngnewproject-name--routing直接enter键(默认都是No
Angular11 and ng-zorro-antd 11 创建一个带路由的ng项目 ng new project-name --routing
直接enter键(默认都是No),不需要选Yes。 进入项目目录 ng serve --open
打开看下一切正常 添加ng-zorro-antd ng add ng-zorro-antd
选项默认 No 语言可以选择中文,模板空模板。
指定文件夹创建两个组件: ng g c componens/one
ng g c componens/two
修改app-routing.module.ts
import { NgModule } from '@angular/core' ; import { Routes, RouterModule } from '@angular/router' ; import { OneComponent } from './componens/one/one.component' ; import { TwoComponent } from './componens/two/two.component' ; const routes: Routes = [ { path: 'one-component' , component: OneComponent, } , { path: 'two-component' , component: TwoComponent} , ] ; @NgModule ( { imports: [ RouterModule. forRoot ( routes) ] , exports: [ RouterModule] } ) export class AppRoutingModule { }
< nav> < ul> < li> < a routerLink &#61; " /one-component" routerLinkActive &#61; " active" > One Component a> li> < li> < a routerLink &#61; " /two-component" routerLinkActive &#61; " active" > Two Component a> li> ul> nav> < div> < router-outlet> router-outlet> div>
运行结果
再添加个布局&#xff0c;效果如下。 项目GitHub 地址 &#xff1a;https://github.com/scqilin/angular11-ng-zorro
ng g c components/hello -m app