I have a bunch of routes:
/gb/
-> name=homepage, page=HomepageGb, locale=en_gb
/es/
-> name=homepage, page=HomepageEs, locale=es_es
/gb/about-us/
-> name=about, page=About, locale=en_gb
/es/sobre-nosotros/
-> name=about, page=About, locale=es_es
/gb/scooter/
-> name=product, page=ScooterGb, code=scooter, locale=en_gb
/gb/:code/
-> name=product, page=GenericProduct, code, locale=en_gb
/gb/promotions/:code/
- name=promotion, page=Promotion, code, locale=en_gb
/some-special-promotion/
- name=promotion, page=Promotion, code=some-special-promotion, locale=en_gb
A few key things I can do:
-
I can iterate over products that come back from our API, and construct links based on the route "name", eg "product" and the product's code, eg "scooter". The fact that some products have completely different page files and URL mount points is irrelevant, I just call
reverse('product', {code: 'scooter', locale: 'en_gb'})
and get the correct URL. This seems to be hard to do with file-system routes. -
I can have have a menu component that can be shared between each locale, that renders links to the homepage and about page. If I render within the context of the
en_gb
locale, I get the GB links, if I render ines_es_
I get the Spain links. Note above that we've even translated the path of the "about" page for Spain. I just callreverse('about', {locale: 'en_gb'})
orreverse('about', {locale: 'es_es'})
and get the correct page. Again, this is hard to do with file-system routes. -
For some promotions I can completely override its URL on the website, without anything else having to change (such as a component that renders a link to a promotion). This does actually happen because some businesses we partner with love their vanity URLs.
Centralised route config has its downsides (mainly in terms of file-size if it grows beyond a few dozen routes), but it also unlocks some powerful use cases. As far as I've been able to see from various examples of file-system routing (in dynamic sites, static is different), not all of these use cases can be satisfied.