svelte-regex-router

0.0.3 • Public • Published

Note

A more detailed README and github repo will be coming soon.

Svelte Regex Router

svelte-regex-router is a simple, lightweight library for you to easily handle routes in your Svelte application.

Personally I had tried a couple options but none really worked, so I made my own.

The way this package works is that it uses document.location.pathname internally, which should be supported by all major browsers (yes, looking at you Internet Explorer), and takes in a Map, transforms the regexs for it, and lets you easily handle each path in it.

Example Usage

App.svelte

<script>
import Router from 'svelte-regex-router';

//Won't be written for sake of brevity
import HelloWorld from './HelloWorld.svelte';

import View404 from './View404.svelte';

const routes = new Map()
  .set('/', () => HelloWorld)
  .set('(.*)', () => View404);
</script>

<Router {routes}>

View404.svelte

<script>
export let params;
const [ path ] = params;
</script>

<h1>404</h1>
<p>Sorry, can't find the path at <b>{path}</b>. Maybe you went on the wrong train stop?</p>

Readme

Keywords

Package Sidebar

Install

npm i svelte-regex-router

Weekly Downloads

1

Version

0.0.3

License

ISC

Unpacked Size

2.77 kB

Total Files

3

Last publish

Collaborators

  • corman