Skip to content

Configuration

How to Configure

Configure the Vite plugin by passing an options object to the router() function in your Vite configuration:

vite.config.ts
ts
import { router } from 'sv-router/vite-plugin';

export default defineConfig({
	plugins: [
		svelte(),
		router({
			path: 'src/pages',
		}),
	],
});

Apply the same options to the CLI in your postinstall script:

package.json
json
{
	"scripts": {
		"postinstall": "sv-router --path src/pages"
	}
}

Options

allLazy

TypeDefaultRequired
boolean
false
No

When set to true, all routes will be lazy loaded by default.

ignore

TypeDefaultRequired
RegExp[]
[]
No

An array of regular expressions for files to ignore when generating routes.

For example, if you want to have Svelte components in your routes directory but don't want them to become routes, you can ignore files that start with a capital letter:

ts
router({ ignore: [/[A-Z].*\.svelte$/] )}

And don't forget to also add the ignore option in your postinstall script:

json
"postinstall": "sv-router --ignore '[A-Z].*\\.svelte$'" // You can have multiple ones separated by commas

js

TypeDefaultRequired
boolean
false
No

When set to true, generates a .js file instead of a .ts file.

path

TypeDefaultRequired
string
src/routes
No

Specifies the directory containing your route files.

Released under the MIT License.