官网https://angular.cn/guide/router
- angular-cli中选中路由,之后app.component.html会多出
```javascript
//相当于vue中
<a name="8L5N9"></a>### 1.一级路由- 一级路由- 路由重定向- 不匹配路由的处理(404)新建四个组件home/about/news/error<a name="1QWA4"></a>#### app-routing.module.ts中配置- **路由重定向和错误处理要放在最后面,不然会出错**```javascriptimport { Routes, RouterModule } from '@angular/router';import { HomeComponent } from './components/home/home.component';import { NewsComponent } from './components/news/news.component';import { AboutComponent } from './components/about/about.component';import { ErrorComponent } from './components/error/error.component';const routes: Routes = [{path:'home',component:HomeComponent},{path:'news',component:NewsComponent},{path:"about",component:AboutComponent},{//路由重定向path:"",redirectTo:"home",pathMatch:"full" //严格匹配 一定要加},{// 匹配没有设置的路由path:"**",component:ErrorComponent}];...export class AppRoutingModule { }
