Astro Partial Dynamic Routing Matching


I am working on a website redo for a website I run making plans to move it from ClassicPress/WordPress to Astro but that website has a significantly more posts and will be using server side rendering. I was having some issues with routing, mainly the issue is the posts structure on this other website would match multiple routes. For example the posts are in a year/month/post folder structure and pages were just pagename. Doing a folder structure like

[year]/[month]/[post]

the year will also match [pagename] creating a conflict. The [year] content is also considered an archive so it would use a different layout than a page. The solution? Well Astro is pretty smart, if you use a partial match like

20[…year]/[month]/[post]

Astro will match the first part of the folder name and make the rest dynamic. This will allow you to create a year archive structure without it also matching your pages. Might come in handy for someone. I know it sure helped solve a problem I was having with dynamic routes.

Categories: tech   astro   web tools