Generate a routing module while creating a module in angular-cli
AngularLazy LoadingAngular CliAngular Problem Overview
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?
Angular Solutions
Solution 1 - Angular
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 generate module [module-name] --routing
or the shorthand version of the command:
ng g m [module-name] --routing
... will create the module and add the mappings/metadata linkings.
Solution 2 - Angular
Module with Routing Create CMD :-
ng g m [ModuleName] --routing
Solution 3 - Angular
Creates both module and routing simultaneously in the same folder.
ng g m sub-folder/module-name --routing
Creates the only module.
ng g m sub-folder/module-name
Solution 4 - Angular
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.
Solution 5 - Angular
Late but very useful.
ng g m about --module app --route about
The above command will generate about module with about component and add lazy load route at app module for routing about route.
Solution 6 - Angular
- 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
Solution 7 - Angular
Solution 8 - Angular
Simple command for Create a Module with routing..
ng g m [module_name] --routing
Solution 9 - Angular
ng generate module ModulName --flat --module=app
Solution 10 - Angular
You can use
// module and routing
-> ng g m name --routing
// component with module and routing
-> ng g c name && ng g m name --routing
-> ng g m name --routing && ng g c name -m=name`