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?
6 Answers
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.
- 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
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.
- 3,002
- 9
- 25
- 40
- 139
- 1
- 5
- To generate component:
ng g c componanentName
orng g c sub-folder/componentName
- To generate module or routing module use:
ng g m sub-folder/moduleName --routing
- 704
- 9
- 16
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.
- 1,471
- 1
- 10
- 8