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

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

主站蜘蛛池模板: 望奎县| 沭阳县| 绥滨县| 元江| 寻乌县| 孟津县| 汉源县| 西藏| 普兰县| 昭觉县| 和静县| 米泉市| 仙桃市| 临泉县| 东辽县| 太湖县| 胶南市| 苏尼特右旗| 五常市| 句容市| 安宁市| 遂宁市| 宁津县| 富锦市| 永济市| 贡觉县| 定远县| 三原县| 财经| 江山市| 渝中区| 达拉特旗| 枝江市| 犍为县| 临漳县| 宝山区| 辰溪县| 仁布县| 沙湾县| 凌云县| 柞水县|