49

I recently started implementing lazy loading in my application. I was wondering whether there is any way to create a routing.module.ts while generating a new module in angular-cli application other than creating it manually?

Saiyaff Farouk
  • 3,135
  • 3
  • 22
  • 35

6 Answers6

100

I was searching about this a bit and found some article which has a very good explanation for different kind of commands.

The Ultimate Angular CLI Reference

So basically, there's no separate command to create routing.module file. But, that can be created while on the creation of the module

ng g module [module-name] --routing or ng g m [module-name] --routing will create the module and add the mappings/metadata linkings.

Saiyaff Farouk
  • 3,135
  • 3
  • 22
  • 35
  • Hi Saiyaff Farouk, the above command creates both module.ts and routing.module.ts together at the same. Is it possible to generate routing.module.ts alone since I already have one module.ts . – Dhana Jul 31 '20 at 17:14
  • 1
    @Dhana I don't think that can be possible with a command for the scenario of 'Is it possible to generate routing.module.ts alone since I already have one module.ts'. To overcome this you can try writing your own schematic. But, let me do a bit of a further research and see whether what you want is available already in any sorta forms – Saiyaff Farouk Aug 04 '20 at 21:01
15

Module with Routing Create CMD :-

ng g m [ModuleName] --routing
8
ng g m sub-folder/module-name --routing

creates both module and routing simultaneously in same folder whereas

ng g m  sub-folder/module-name

creates only module.

enter image description here

Milo
  • 3,002
  • 9
  • 25
  • 40
Chaman Bharti
  • 139
  • 1
  • 5
4
  1. To generate component: ng g c componanentName or ng g c sub-folder/componentName
  2. To generate module or routing module use: ng g m sub-folder/moduleName --routing
Harrison O
  • 704
  • 9
  • 16
2
ng generate module ModulName --flat --module=app
double-beep
  • 3,889
  • 12
  • 24
  • 35
2

I am late to the party :) but here is how I generate a module, routing for the module and component all at one go and inside the same directory

From the src/app/ directory type in the following command to generate a module, routing and component called 'my-page'

ng g m my-page --routing=true && ng g c my-page --skip-tests=true -m=my-page

If you want the tests to be generated then do not use the skip-tests argument.

sunitkatkar
  • 1,471
  • 1
  • 10
  • 8