Skip to content

task#13 add routing file

bacn edited this page Sep 16, 2020 · 1 revision

Add routing file

This chapter can be skipped if the project has been created with a routing.

  1. Add app-routing.module.ts in folder ./src/app
  2. Import RouterModule and Routes from @angular/router
  3. Export an empty routes array
  4. Export your router created with RouterModule.forRoot()
  5. Export class AppRoutingModule { }

Result

The result is the same as in the last task.

Hints

Imports:

Add the file app-routing.module.ts in the folder ./src/app and add the code import { Routes, RouterModule } from '@angular/router';

Defining Routes

Define a routes array:

export const routes: Routes = [];

Create your app router module

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

Final file app-routing.module.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 { }

Clone this wiki locally