svelte-router-file
v0.1.5
Published
This is a plugin package for [@svelte-router/core](https://github.com/WJSoftware/svelte-router), which should be installed. It follows the routing format established by [sv-router](https://sv-router.vercel.app/guide/file-based/route-definition). # Install
Maintainers
Readme
What this is
This is a plugin package for @svelte-router/core, which should be installed. It follows the routing format established by sv-router.
Installation
npm i svelte-router-fileUsage
- Initialize the library
- Mount the FileRouter
Initializing the library
Initialize the library in 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();Initializing the FileRouter
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} />