I'm experimenting with making a hybrid site and a dynamic route to automatically redirect users to the correct part of the site based on their preferred language. Is there any way I can check whether a route is valid before redirecting a user to it? So far I have tried using Object.keys import.meta.globs("./**), but that seems to return a list of files, not a list of routes.
#How to check if a string is a valid Astro route?
6 messages · Page 1 of 1 (latest)
If these routes are collection based then you can just query that collection and redirect if the language/slug exists
They're not exclusively collection based.
I guess they...could be?
How they are defined now? You could also just filter the list of files down to the ones you want
In my testing site there's only file-based pages, but in the final site I expect there to be a mix of file-based and collection-based routing. I could probably switch it to being entirely collection-based, but that would be a lot of work.