Reputation: 6221
The Angular documentation and Angular CLI push the Angular beginner (I'm in this boat) to implement application routing in a separate module from the main application, without really explaining why it gets this special treatment. For example, when I scaffold a new Angular project with routing using the CLI, I get a app-routing.module.ts
file when is imported in my main app.module.ts
file.
I have read the it's because of Separation of Concerns, but I have a hard time accepting this as the entire reason, because there are multiple concerns in an application, yet only routing is gets its own module.
As a beginner in Angular, I have no idea if this is an opinion based question, or there is a legitimate technical reason why it's a good idea. I can't find any information one way or the other, which is why I'm asking.
For those Angular veterens who have worked on medium-largish applications, when do you put or not put your application routing in a separte module, and why? Does it become technically necessary at a certain point, or is this simply a organizational convention?
Thanks.
Upvotes: 3
Views: 112
Reputation: 1944
It's all about separation of concerns. While you may be tempted to but the entire app logic in a single module, it's usually recommended to separate each concern to a separate module. A module defining views that display product info, should not worry directly how and when its views are rendered. Decoupling different logic areas from each other, will make your code cleaner and more maintainable.
Upvotes: 2