Creating routes

 Now that we have a data source and a service to interact with this data source, it's time to start working on the routes and components that will consume this data. Add a routes.ts file to the app folder with the following configuration:

import { Routes } from '@angular/router';import { HomeComponent } from './home/home.component';import { PostComponent } from './post/post.component';export const routes: Routes = [  {    path: '',    component: HomeComponent  },  {    path: 'post/:id',    component: PostComponent  }]

The second route that points to post has a :id placeholder. This is used to define a dynamic route, which means that the value passed in as ID can be used to control the behavior of the mounted component.

Create the two components ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.