This is not a problem at all.
Just add routing manually.
All that the --routing flag is --routing , in addition to adding <router-outlet></router-outlet> to app.component.html , is adding RouterModule.forRoot() q RouterModule.forRoot() to a separate module called AppRoutingModule and inclusion of this module in imports AppModule .
So, in app.module.ts , it adds an AppRoutingModule to the imports your AppModule .
AppRoutingModule defined as app-routing.module.ts , which is created from this template .
It is very small that I copy this here:
import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ { path: '', children: [] } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { }
{path: '', children:[]} is just a placeholder that you have to replace (I know, because I added it to the source code). It simply ensures that the router will not complain about the <router-outlet> when you have no routes.
So, back to the question, what to do? Or copy the file into your project so that it looks exactly the same as the original CLI and add the AppRoutingModule to your imports AppModule ...
Or just add RouterModule.forRoot([/* routes here */]) instead of imports your AppModule . This will still work, with built-in support for deferred loading, and everything else works just fine.
PS
Remember that to add child routes you can always generate more modules with routing and ng generate module Foo --routing whether you used the --routing flag with ng new or not. No configuration or any magic to worry about.
Meligy
source share