Generate a routing module while creating a module in angular-cli

AngularLazy LoadingAngular Cli

Angular 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

enter image description here

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

  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

Solution 7 - Angular

you can test this
code

ng g m landing --route landing --module app 

enter image description here

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`

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaiyaff FaroukView Question on Stackoverflow
Solution 1 - AngularSaiyaff FaroukView Answer on Stackoverflow
Solution 2 - AngularThai Mozhi KalviView Answer on Stackoverflow
Solution 3 - AngularChaman BhartiView Answer on Stackoverflow
Solution 4 - AngularsunitkatkarView Answer on Stackoverflow
Solution 5 - AngularSantoshView Answer on Stackoverflow
Solution 6 - AngularHarrison OView Answer on Stackoverflow
Solution 7 - AngularAlbazView Answer on Stackoverflow
Solution 8 - AngularSoft Dev Ahmad yar khanView Answer on Stackoverflow
Solution 9 - AngularAqleem OrakzaiView Answer on Stackoverflow
Solution 10 - AngularSiddhartha MukherjeeView Answer on Stackoverflow