Socket
Book a DemoInstallSign in
Socket

svelte-regex-router

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-regex-router

A simple, lightweight router for Svelte that uses regex

0.0.3
latest
npmnpm
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

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>

Keywords

svelte

FAQs

Package last updated on 29 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.