官术网_书友最值得收藏!

Adding a new route 

As you saw previously, routes are part of every web application. Now, we will add a new route, so that we can access the content of our beers module. Open src/app/app-routing.module.ts and replace the code with the following:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { BeersComponent } from './beers/beers.component';
const routes: Routes = [
{ path: '', redirectTo: 'beers', pathMatch: 'full' },
{ path: 'beers', component: BeersComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

Note that we are just adding the new route to an existing route file (in this case, app.routing.module.ts), as this example is extremely simple. But, in larger applications, it is recommended that you create individual route files for each application module

主站蜘蛛池模板: 鄂尔多斯市| 桑日县| 长兴县| 开封县| 新乡市| 汕尾市| 孙吴县| 农安县| 伊吾县| 巩义市| 西和县| 双峰县| 沭阳县| 手机| 衡阳县| 根河市| 长沙市| 阿拉善右旗| 松原市| 清流县| 措勤县| 拜泉县| 开江县| 大城县| 武安市| 江门市| 河北区| 稷山县| 繁峙县| 武清区| 成安县| 丰原市| 定州市| 奉贤区| 镇平县| 安仁县| 宜宾市| 拉孜县| 新乡市| 湟中县| 清徐县|