1

I have a project structure similar to something like this:

app.module
–– dashboard.module
–– overview.module
–––– profile.module
–––––– favorites.module

What you see are four levels of feature modules. (Consider them to have also multiple components etc.)


What would be the best way of setting up routing for these modules?

I would set up a routing module for every module, like this: app-routing.module, dashboard-routing.module, overview-routing.module (...)

But is that considered as a good practice in Angular? If not, what should one do instead?

1

2 Answers 2

1

Each module should have their own routing file so the concerns remain separate. Its a good practice and i think you should go with this approach.

For Example, an Authentication module should handle its own routing like: /login, /signup, /forgot-password etc.

Sign up to request clarification or add additional context in comments.

2 Comments

I agree on that so far.
@L.Heider Thanks :) could you please accept this answer?
0

In my opinion, you should not create multiple modules for a single type of interface. In your case there is a single application and a single module app.module is enough for it.

Now the question is that the alternate approach for another modules ?

So you should create Components for Dashboard, Overview, Profile, Favourites and manage routes in single app-routing.module file.

One more thing which should keep in mind, if you have multiple user interface like admin, sub-admin, user, etc. then it would be easy to maintain modules for each interface, and can manage their routing separately.

2 Comments

But what if I like to implement lazy loading?
Yes in that case you must go with the Module structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.