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

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

主站蜘蛛池模板: 合肥市| 凤台县| 辛集市| 通渭县| 汉沽区| 吴忠市| 拜城县| 广州市| 岳普湖县| 彭州市| 重庆市| 永定县| 邛崃市| 土默特右旗| 泊头市| 泰宁县| 镶黄旗| 尚志市| 南安市| 马鞍山市| 云霄县| 满洲里市| 阿坝县| 都兰县| 遵义市| 婺源县| 安阳市| 阜宁县| 两当县| 长海县| 喀喇| 定安县| 广河县| 桂平市| 贵南县| 宜川县| 化德县| 安达市| 新建县| 抚顺县| 宜君县|