DEV Community

Discussion on: Build nested routes in nodejs using grandjs

Collapse
 
tareksalem profile image
tareksalem

this is a good question, express easily can append routes as you explained in the example, but what about if you don't want to add /posts to use another group of routes so simply you want to do something like the following:

adminRouter.use(postRouter)

and also you have for example categories router you want to append to /admin directly so you will have something like the following:following:

adminRouter.use(postRouter)
adminRouter.use(categoriesRouter) 

this will work fine, but what about if you want to add some middlewares on the post router however you don't make these middlewares applied in categories router ??
you will find that all routes in the admin router have the middlewares of a specific router which is an isolation problem, to understand what I mean you can test this example:

This problem is solved in grandjs.
Actually grandjs include a lot of benefits, but this example to elaborate the difference.