banner



How To Create A Routing Module In Angular

8 Answers 8

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.

answered Mar 1 '17 at 7:45

2

  • 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 .

    Jul 31 '20 at 17:14

  • @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

    Aug 4 '20 at 21:01

Module with Routing Create CMD :-

              ng g m [ModuleName] --routing                          

answered Feb 13 '19 at 10:09

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

Amir

8,421 6 gold badges 43 silver badges 47 bronze badges

answered Oct 23 '19 at 17: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.

answered Apr 3 at 0:32

  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

answered Aug 26 '19 at 11:51

you can test this
code

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

enter image description here

answered Nov 7 at 22:48

              ng generate module ModulName --flat --module=app                          

double-beep

4,173 13 gold badges 27 silver badges 38 bronze badges

answered Jun 20 '19 at 2:03

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.

answered Sep 14 at 8:15

Not the answer you're looking for? Browse other questions tagged angular lazy-loading angular-cli or ask your own question.

How To Create A Routing Module In Angular

Source: https://stackoverflow.com/questions/42502449/generate-a-routing-module-while-creating-a-module-in-angular-cli

Posted by: gordonhatelve.blogspot.com

0 Response to "How To Create A Routing Module In Angular"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel