Dynamic routing with _.sql#941
Dynamic routing with _.sql#941andrewsinnovations wants to merge 5 commits intosqlpage:mainfrom andrewsinnovations:main
Conversation
This update allow you to create a _.sql file that will catch all routing paths in its folder.
Clippy returned errors for routing, and also an unrelated block of code with a redundant else block.
|
This functionality could possible be achieved with the existing 404.sql functionality. However that method indicates a "file not found" intended use, rather than allowing for dynamic routes. If a file named _.sql is used by convention for a dynamic catch-all, its purpose is more obvious. |
|
Hi ! Could you walk me through ? The goal is to avoid having to name catch-all files |
|
Yes the intention is solely semantics, with _ and 404 having different meanings. I ran some tests with 404.sql and the functionality is the same. If you'd rather only offer 404 handling for unknown routes, I think that will work and can close the PR. |
|
Ok ! I have been thinking about ways to improve routing, I'll make my own PR and let you know ! |
This update allow you to create a _.sql file that will catch all routing paths in its folder and all subpaths, while still respecting the 404.sql process already in place.
For example, if your folder structure is such:
/
/models
/models/_.sql
/models/example/404.sql
and if you have this code in the /models/_.sql:
and you have this code in /models/example/404.sql:
In your browser, you can access any of these URLs with this result:
This allows for some simple dynamic routing.