Angular 2 Example for routes such as /route/subroute for static urls Basic route example with sub routes tree

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

app.module.ts

 import {routes} from "./app.routes";

 @NgModule({
    declarations: [AppComponent],
    imports: [BrowserModule, mainModule.forRoot(), RouterModule.forRoot(routes)],
    providers: [],
    bootstrap: [AppComponent]
 })

 export class AppModule { } 

app.routes.ts

import { Routes } from '@angular/router';
import {SubTreeRoutes} from "./subTree/subTreeRoutes.routes";

export const routes: Routes = [
  ...SubTreeRoutes,
  { path: '',  redirectTo: 'home', pathMatch: 'full'}
];

subTreeRoutes.ts

import {Route} from '@angular/router';
import {exampleComponent} from "./example.component";

export const SubTreeRoutes: Route[] = [
  {
    path: 'subTree',
    children: [
      {path: '',component: exampleComponent}
    ]
  }
];


Got any Angular 2 Question?