-
-
Save tomatrow/46c5d5360e5ebf11c49124b3f147ac24 to your computer and use it in GitHub Desktop.
Revisions
-
tomatrow revised this gist
Dec 4, 2020 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ { "name": "singularity-router", "dependencies": { "url-pattern": "^1.0.3" } } -
tomatrow revised this gist
Dec 4, 2020 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ { "name": "singularity-router" } -
RedHatter created this gist
Dec 4, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ <script> import UrlPattern from 'url-pattern' import location, { navigate, noMatch } from './location.js' export let path export let component = undefined export let redirect = undefined $: pattern = new UrlPattern(path) $: router = { params: pattern.match($location), path: $location, } $: { if (router.params !== null) { $noMatch = false if (redirect) navigate(redirect, true) } } </script> {#if router.params !== null} {#if component} <svelte:component this={component} {router} {...$$restProps} /> {:else} <slot {router} /> {/if} {/if} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import { writable } from 'svelte/store' const location = writable(window.location.pathname) export default location export let noMatch = writable(true) location.subscribe(_ => noMatch.set(true)) window.addEventListener('popstate', e => location.set(window.location.pathname)) let hasPrevious = false export function navigate(_path, replace = false) { hasPrevious = true const fn = replace ? 'replaceState' : 'pushState' history[fn](null, '', _path) location.set(window.location.pathname) } export function back() { if (hasPrevious) history.back() else navigate(window.location.pathname.replace(/[^/]+\/?$/, '')) }