Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSua Morales
2,651 PointsWhy is it beneficial to use the same routes? Why wouldn't you just change the route?
Why wouldn't you just use a unique route?
1 Answer
Garrett Darnell
18,751 PointsThe question of "why make something modular?" is a common one. It might seem like the modular approach is more work up front, and sometimes it is, but it's usually worth it in the long run. Modular design makes it easier for you and others to read and understand your code in the future, and it'll make changing things in the future quite a bit easier.
As a simple example, let's say you build a site for a client, and they want the following routes for their online store:
/products/
/products/mens
/products/womens
/products/kids
Months go by, and now the client wants to split the "products" route into three different routes, like this:
/apparel/
/apparel/mens
/apparel/womens
/apparel/kids
/shoes/
/shoes/mens
/shoes/womens
/shoes/kids
/swimwear/
/swimwear/mens
/swimwear/womens
/swimwear/kids
If you have the mens, womens, kids
routes separated out into their own namespace from the beginning, it's trivial to meet the client's request and apply those routes to apparel, shoes, and swimwear
instead of products
.
Alternatively, let's say they want to change it from products
to items
. If you have a products
router set up with /mens/, /womens/,
and /kids/
routes, then all you have to do is change the name of the products
router, as opposed to having to change every route individually.