├── module.d.ts ├── doc ├── examples │ ├── mock │ │ ├── Home.svelte │ │ ├── Page1.svelte │ │ ├── Page2.svelte │ │ ├── Page3.svelte │ │ ├── NotFound.svelte │ │ └── SubRoutes │ │ │ ├── SubRoute2.svelte │ │ │ ├── SubRoute1.svelte │ │ │ └── index.svelte │ ├── Basic.svelte │ ├── Redirect.svelte │ ├── Fallback.svelte │ ├── HashRoute.svelte │ ├── Protected.svelte │ ├── AdvancedRedirect.svelte │ ├── BeforeLeave.svelte │ └── Lazy.svelte ├── main.js ├── icons │ ├── arrowLeft.svg │ ├── night.svg │ └── day.svg ├── components │ ├── LazySvg │ │ ├── cache.js │ │ └── index.svelte │ ├── Menu.svelte │ ├── Example │ │ ├── index.svelte │ │ └── AddressBar.svelte │ ├── MenuButton │ │ └── index.svelte │ ├── Header │ │ └── index.svelte │ └── Layout.svelte ├── pages │ ├── Home.svelte │ └── Examples.svelte ├── App.svelte └── theme │ ├── themeStore.js │ ├── index.svelte │ └── Switcher.svelte ├── .npmignore ├── src ├── examples │ ├── components │ │ ├── Home.svelte │ │ ├── Page1.svelte │ │ ├── Page2.svelte │ │ ├── Page3.svelte │ │ ├── NotFound.svelte │ │ ├── MainLayout.svelte │ │ └── SubRoutes │ │ │ ├── SubRoute1.svelte │ │ │ ├── SubRoute2.svelte │ │ │ └── index.svelte │ ├── main.js │ ├── Basic.svelte │ ├── ssr.js │ ├── Redirect.svelte │ ├── Fallback.svelte │ ├── NavLink.svelte │ ├── HashRoute.svelte │ ├── SubRoutes.svelte │ ├── Layout.svelte │ ├── Protected.svelte │ ├── BeforeLeave.svelte │ ├── AdvancedRedirect.svelte │ └── Lazy.svelte └── Router │ ├── BrowserRouter.svelte │ ├── MemoryRouter.svelte │ ├── utils │ ├── basePath.js │ ├── fragment.js │ ├── lazyCache.js │ ├── protection.js │ ├── history │ │ ├── index.js │ │ ├── baseHistory.js │ │ ├── memoryHistory.js │ │ └── browserHistory.js │ ├── dynamicDerived.js │ ├── matchPath.js │ └── register.js │ ├── Protected.svelte │ ├── Lazy.svelte │ ├── Layout.svelte │ ├── Redirect.svelte │ ├── BeforeLeave.svelte │ ├── index.js │ ├── Fallback.svelte │ ├── BaseRouter.svelte │ ├── links.js │ ├── navLink.js │ ├── HashRoute.svelte │ └── Route.svelte ├── public ├── favicon.png ├── index.html └── global.css ├── prettier.config.js ├── .gitignore ├── LICENSE.md ├── package.json ├── rollup.config.js ├── README.md └── logo.svg /module.d.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/examples/mock/Home.svelte: -------------------------------------------------------------------------------- 1 |
Home
2 | -------------------------------------------------------------------------------- /doc/examples/mock/Page1.svelte: -------------------------------------------------------------------------------- 1 |
Page1
2 | -------------------------------------------------------------------------------- /doc/examples/mock/Page2.svelte: -------------------------------------------------------------------------------- 1 |
Page2
2 | -------------------------------------------------------------------------------- /doc/examples/mock/Page3.svelte: -------------------------------------------------------------------------------- 1 |
Page3
2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | logo.svg 2 | prettier.config.js 3 | doc/** 4 | -------------------------------------------------------------------------------- /src/examples/components/Home.svelte: -------------------------------------------------------------------------------- 1 |
Home
2 | -------------------------------------------------------------------------------- /src/examples/components/Page1.svelte: -------------------------------------------------------------------------------- 1 |
Page1
2 | -------------------------------------------------------------------------------- /src/examples/components/Page2.svelte: -------------------------------------------------------------------------------- 1 |
Page2
2 | -------------------------------------------------------------------------------- /src/examples/components/Page3.svelte: -------------------------------------------------------------------------------- 1 |
Page3
2 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qutran/swheel/HEAD/public/favicon.png -------------------------------------------------------------------------------- /doc/main.js: -------------------------------------------------------------------------------- 1 | import App from './App'; 2 | 3 | new App({ 4 | target: document.body, 5 | }); 6 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | singleQuote: true, 3 | trailingComma: 'all', 4 | }; 5 | -------------------------------------------------------------------------------- /doc/examples/mock/NotFound.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |
Page not found :(
8 | -------------------------------------------------------------------------------- /src/examples/components/NotFound.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |
Page not found :(
8 | -------------------------------------------------------------------------------- /doc/icons/arrowLeft.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | public/bundle.* 4 | public/main.* 5 | public/ssr.* 6 | public/chunk* 7 | public/Page* 8 | dist 9 | dist_doc 10 | package-lock.json 11 | stats.html -------------------------------------------------------------------------------- /doc/components/LazySvg/cache.js: -------------------------------------------------------------------------------- 1 | const cache = {}; 2 | 3 | export function loadSvg(src) { 4 | cache[src] = cache[src] || fetch(src).then(payload => payload.text()); 5 | return cache[src]; 6 | } 7 | -------------------------------------------------------------------------------- /src/examples/components/MainLayout.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 |
12 | 13 |
14 | -------------------------------------------------------------------------------- /doc/examples/mock/SubRoutes/SubRoute2.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 |
SubRoute2
12 | -------------------------------------------------------------------------------- /doc/examples/mock/SubRoutes/SubRoute1.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 |
SubRoute1
12 | -------------------------------------------------------------------------------- /src/examples/components/SubRoutes/SubRoute1.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 |
SubRoute1
12 | -------------------------------------------------------------------------------- /src/examples/components/SubRoutes/SubRoute2.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 |
SubRoute2
12 | -------------------------------------------------------------------------------- /doc/pages/Home.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 |
13 | {@html Doc} 14 |
15 | -------------------------------------------------------------------------------- /src/Router/BrowserRouter.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Router/MemoryRouter.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Router/utils/basePath.js: -------------------------------------------------------------------------------- 1 | import { getContext, setContext } from 'svelte'; 2 | 3 | const CONTEXT_KEY = '_base_path'; 4 | 5 | export function createBasePath(basePath) { 6 | setContext(CONTEXT_KEY, basePath); 7 | } 8 | 9 | export function getBasePath() { 10 | return (getContext(CONTEXT_KEY) || '').replace(/\/$/, ''); 11 | } 12 | -------------------------------------------------------------------------------- /src/Router/Protected.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Router/utils/fragment.js: -------------------------------------------------------------------------------- 1 | export function fragment(node) { 2 | node.parentElement.appendChild(node.content); 3 | node.setAttribute('style', 'display: none;'); 4 | 5 | return { 6 | destroy() { 7 | if (node && node.parentElement) { 8 | node.parentElement.removeChild(node.content); 9 | } 10 | }, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /doc/examples/mock/SubRoutes/index.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /src/examples/components/SubRoutes/index.svelte: -------------------------------------------------------------------------------- 1 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Svelte app 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Router/Lazy.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | {#await promise} 12 | 13 | {:then loadedComponent} 14 | 15 | {:catch} 16 | 17 | {/await} 18 | -------------------------------------------------------------------------------- /doc/App.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/examples/main.js: -------------------------------------------------------------------------------- 1 | import App from './Basic'; 2 | // import App from './NavLink'; 3 | // import App from './Fallback'; 4 | // import App from './Redirect'; 5 | // import App from './AdvancedRedirect'; 6 | // import App from './HashRoute'; 7 | // import App from './SubRoutes'; 8 | // import App from './Protected'; 9 | // import App from './BeforeLeave'; 10 | // import App from './Lazy'; 11 | // import App from './Layout'; 12 | 13 | export default new App({ 14 | target: document.body, 15 | }); 16 | -------------------------------------------------------------------------------- /doc/icons/night.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Router/utils/lazyCache.js: -------------------------------------------------------------------------------- 1 | const cache = new Map(); 2 | 3 | function createThrottling(ms) { 4 | return new Promise(resolve => setTimeout(resolve, ms)); 5 | } 6 | 7 | export async function getPromiseFromCache(component, throttle) { 8 | if (!cache.has(component)) { 9 | const promise = Promise.all([component(), createThrottling(throttle)]).then( 10 | ([loadedComponent]) => loadedComponent, 11 | ); 12 | 13 | cache.set(component, promise); 14 | } 15 | 16 | return cache.get(component); 17 | } 18 | -------------------------------------------------------------------------------- /doc/components/LazySvg/index.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | {#await promise} 18 | 19 | {:then text} 20 |
21 | {@html text} 22 |
23 | {:catch} 24 | 25 | {/await} 26 | -------------------------------------------------------------------------------- /src/Router/Layout.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | {#if $isAnyMatch} 15 | 16 | 17 | 18 | {:else} 19 | 20 | {/if} 21 | 22 | -------------------------------------------------------------------------------- /src/examples/Basic.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | to home 10 | to page 1 11 | to page 2 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/components/Menu.svelte: -------------------------------------------------------------------------------- 1 | 25 | 26 |