This is a plugin package for @svelte-router/core, which should be installed. It follows the routing format established by sv-router.
npm i svelte-router-file
main.js or similar, before any FileRouter is mounted:import { init } from "svelte-router-file";
/* basePath is set to ./routes if not specified */
init({ basePath: "./myroutes" });
Initializing this library means that you should not call the usual init() function of @svelte-router/core.
// BAD:
import { init } from "@svelte-router/core";
init();
In the root component, like App.svelte or similar:
<script lang="ts">
import { FileRouter } from "svelte-router-file";
let files = import.meta.glob("routes/**/*.svelte", { eager: true });
</script>
<FileRouter {files} />