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.
Because it's not usually the case, may be another command like
ng g module routing x
instead of ng g module x
Namaste
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 asome.module.ts
andsome-routing.module.ts
file.
ng generate module SomeModule --routing
(orng 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._
Most helpful comment
Have you tried the
--routing
flag when generating a module? This will generate you asome.module.ts
andsome-routing.module.ts
file.ng generate module SomeModule --routing
(orng g m SomeModule --routing
, for short)