Creating a Router-first app

With the Router-first approach, we will want to enable routing early on in our application:

  1. You can create the new application with routing already configured by executing this command:

Ensure that @angular/cli is not installed globally, or you may run into errors:

$ npx @angular/cli new lemon-mart --routing
  1. A new AppRoutingModule file has been created for us:
src/app/app-routing.modules.ts
import { NgModule } from '@angular/core';import { Routes, RouterModule } from '@angular/router';const routes: Routes = [];@NgModule({  imports: [RouterModule.forRoot(routes)],  exports: [RouterModule]})export class AppRoutingModule { }

We will be defining routes inside the routes array. Note that routes array is passed in ...

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.