Adding Routes

An Example Router

Your components and routes will be different for each app, but everything else in the router module will be the same.

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [];

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

export class AppRoutingModule { }


Stackblitz Demo

Angular Routing

Route Order

One of the key things to know about routing configuration is that the order matters a lot. When the router receives an URL, it will start going through the routes array in order: starting with the first index of the configuration array. If it finds a match to the complete URL, it stops and instantiates

Last updated