I have created a module in using angular CLI and forget to add --routing while it's creation, now i want to add a routing module to it.
ng init --routing won't help in angular CLI version 1.1.1
I have created a module in using angular CLI and forget to add --routing while it's creation, now i want to add a routing module to it.
ng init --routing won't help in angular CLI version 1.1.1
ng generate module app-routing --module app --flat
app with the name of your existing moduleapp-routing with the name to give the routing moduleIn the new module, add appRoutes and RouterModule.forRoot or RouterModule.forChild.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';
const appRoutes: Routes = [
{ path: 'some-path', component: SomeComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}
<router-outlet></router-outlet> to your component if needed (e.g., app.component.html)