Angular-cli: Create a route module when generating a module

Created on 23 Nov 2016  路  12Comments  路  Source: angular/angular-cli

Routing_module

According to angular documentation, it's considered the best practice to add routing module for each module, so my suggestion is, when generating a module, i think it makes sense to create a route module for it.

update

Because it's not usually the case, may be another command like
ng g module routing x instead of ng g module x
Namaste

Most helpful comment

Have you tried the --routing flag when generating a module? This will generate you a some.module.ts and some-routing.module.ts file.

ng generate module SomeModule --routing (or ng g m SomeModule --routing, for short)

All 12 comments

Have you tried the --routing flag when generating a module? This will generate you a some.module.ts and some-routing.module.ts file.

ng generate module SomeModule --routing (or ng g m SomeModule --routing, for short)

I didn't know about that command!
thanksss

@delasteve Can u update the readme with this feature for others?

https://github.com/angular/angular-cli/wiki/module

Additionally, @Brocco has a PR out there to move the docs to the repo https://github.com/angular/angular-cli/pull/3382

And if I need the html , scss annd the component of this ?

Hi @delasteve, I tried using your method for generating routing module. But it seems like it doesn't do the trick. I have another just-module.ts file in my directory. When I try to generate routing module, the latest versioned angular-cli I am using throws me an error of already-existing-module inside the directory.

@waleedshkt If the module already exists, the CLI will throw errors. Just delete that file and then run the command again with the --routing flag.

@josephdgb1996 You just generate a component with the same name as your module. Using the example @delasteve gave you'd just run ng generate component SomeModule.

ng g m moduleName --routing

Have you tried the --routing flag when generating a module? This will generate you a some.module.ts and some-routing.module.ts file.

ng generate module SomeModule --routing (or ng g m SomeModule --routing, for short)

Thanks. Did not know such command exists. This works perfect !

@josephdgb1996 module does not have html or scss.
module has components wich has the html and stylesheets like css, scss, etc...

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rwillmer picture rwillmer  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

sysmat picture sysmat  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments