DEV Community

Discussion on: Angular Routing - Best Practices for Enterprise Applications

Collapse
 
michaeljota profile image
Michael De Abreu

I'm surprise for this recommendations. There are not only against the Angular Style Guide, but it require extra work from your team if you are using Angular CLI, or any UI that uses the CLI underneath. I would like to give my feedback about this, I hope you don't mind.

I find the router module to be very useful, you could even use it for the components that you are routing, as they are not supposed to be used else where.

Guards are just another kind of services, and thus they should be placed in the CoreModule, if you are using them as app wide services. I do like the idea of placing feature specific guards aside that feature module. However, if you place them all in CoreModule, you can use them in any part of the application, even in features modules.

In the same order of ideas, barrer files are discourage by the Angular Team, but for a good reason: They are not good for tree shaking. Also, they could produce circular dependency errors, but this is really unlikely.

Finally, and I guess this would be the most banal feedback, I wouldn't name a folder with a leading underscore, but I understand that with this you can find those folders better.

Collapse
 
wesgrimes profile image
Wes

Thanks for the feedback Michael. I appreciate your opinion! It is always great to get feedback on articles that I write.

The concepts laid out in my article are recommendations and preferences. I realize others may not wish to implement ideas in the same manner, and that's OK.

I use the Angular CLI exclusively and these best practices work great with the CLI.

That being said, I would like to counter your claims with the following:

  • On Barrel index.ts exports: John Papa and Todd Motto both use barrel exports heavily, it's where I got the idea from. You can see their repos here using barrels: github.com/johnpapa/heroes-angular... and Todd's tweet for reference: twitter.com/toddmotto/status/91881...

  • On Folders with leading underscore: This is just a recommendation, and it works fantastic for my team. I have not run across any negative consequences from this. It's quite common out in the wild with several high starred github repos using this.

  • On Guards - I agree they are a type of service, but they have very unique use-cases, and can only be used directly with route definition. This is why I store them close to the source of use.

Collapse
 
wesgrimes profile image
Wes

And again thanks for the feedback. I always appreciate it! Hope you’re having a great day!

Collapse
 
michaeljota profile image
Michael De Abreu

I have admiration for both, but I also have found that this patterns doesn't fit with Angular very well. They are more like React, or Vue. You can use them, but they don't fit. I don't know if I explain myself. However, it's like you said, sometimes, sometimes not.

Thread Thread
 
wesgrimes profile image
Wes

Well thanks again for your feedback! Would love to see how you’re building Angular apps for comparison sake. Maybe I’m missing something. If you haven’t already, how about writing an article?

Thread Thread
 
michaeljota profile image
Michael De Abreu

Sure do. I have already write a couple, but nothing specific to organization structure, as I have found the Angular Style Guide a really good approach to manage. I have work in a couple of projects with Angular, and in all of them we always followed the ASG. Sometimes we add something, or adjust something, but it would still the recommended structure.

Thread Thread
 
wesgrimes profile image
Wes

That’s great! I am a big fan of the style guide. I use it as a base for most things, but I do on occasion break from the norm where it makes sense for my team and our deliverables. Have a great day!