Routing
DinoSsr is an experimental work in progress and subject to change!
Routes are .svelte
files nested inside the
routes
directory.
Routes can export a pattern
to extend the pathname using the
URL Pattern API.
For example:
routes/ | Pattern export | URL pathname |
---|---|---|
index.svelte | / | |
about.svelte | /about | |
docs/index.svelte | /docs/ | |
docs/routing.svelte | / | /docs/routing/ |
blog/index.svelte | /:slug/ | /blog/hello-world/ |
blog/(post)/index.svelte | /:year(\\d+)/:month(\\d+)/:slug/ | /blog/2023/11/hello-world/ |
Trailing slashes are controlled by using an index.svelte
page or by exporting a pattern ending with a slash.
Using parentheses around a directory name removes it from the URL pathname.
Patterns are exported from the Svelte component module script.
<script context="module">
export const pattern = '/:year(\d+)/:month(\d+)/:slug/';
</script>
For JavaScript routes see advanced routes. Auto-generated routes are compiled and bundled just-in-time. If you need large 3rd party libraries use middleware instead.