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

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

主站蜘蛛池模板: 福清市| 曲阜市| 长沙县| 尚义县| 伊金霍洛旗| 项城市| 南陵县| 泗阳县| 翁牛特旗| 乳山市| 辽阳县| 寿阳县| 富宁县| 荔浦县| 曲阜市| 满城县| 高阳县| 济阳县| 绥江县| 双辽市| 资兴市| 崇明县| 长子县| 安吉县| 乐至县| 涿州市| 溆浦县| 平武县| 宣武区| 寿光市| 宁远县| 南部县| 西城区| 治多县| 高阳县| 施甸县| 东乡| 新民市| 邯郸县| 乌兰察布市| 辽源市|