上QQ阅读APP看书,第一时间看更新
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.