It's common to have routes within routes, in large web applications – that is, to have a parent/id/child/id/grandchild type of routing situation. But how do you handle such large, complex routing needs? How do you ensure that you have access to the parent object when looking at the child or grandchild, as well? These questions can lead to some confusion and even some bad decisions in routes and route handlers.
Fortunately, the solution is fairly simple – and something that you've already seen a little bit of. Express supports the idea of sub-routes, by allowing one router to “use” another router. Within those sub-routes, gaining access to the data that was loaded by the parent routes is almost trivial.
In this episode, then, I'll show you how to use sub-routes in your Express apps, gain access to the parent objects from the child routes, and show you how this method of organizing routes will help to keep your code sane.