Is there a command for Angular CLI, wherein I can generate a routing.ts file? So far I have only researched for ng g m moduleName --routing
which is not I want, because it only created module-Name-routing.module.ts
. What I want is module-Name.routing.ts. Please help. Thank you
CodePudding user response:
By convention, routing modules end with module.ts
just like any other modules. Angular will not generate a file ending with routing.ts
. You would have to manually change the file name, then update the import in app.module.ts
, but I don't really see the point.
You can follow this tutorial to add a routing module:
https://angular.io/tutorial/toh-pt5
You can specify the name of the routing module during this command
ng generate module your-name-here --flat --module=app
If you insist on going against convention, then generate the module as above and change the file name manually. Then go to app.module.ts
and you will see an import similar to this one:
import { MyRoutingModule } from './my-module-name.module';
Correct the import statement and you're good to go
import { MyRoutingModule } from './my-module-name.routing';