-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b04827
commit 75ece5a
Showing
12 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Test app | ||
test/app | ||
test/app | ||
|
||
# Compiled | ||
examples/*/dist |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf8"> | ||
<meta name="viewport" content="width=device-width"> | ||
|
||
<title>svelte-spa-router sample</title> | ||
</head> | ||
|
||
<body> | ||
<script defer type="module" src="main.js"></script> | ||
</body> | ||
</html> |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import svelte from 'rollup-plugin-svelte' | ||
import resolve from '@rollup/plugin-node-resolve' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
|
||
export default { | ||
input: 'src/main.js', | ||
output: { | ||
sourcemap: true, | ||
name: 'app', | ||
format: 'esm', | ||
dir: 'dist/', | ||
chunkFileNames: '[name].js' | ||
}, | ||
plugins: [ | ||
svelte({ | ||
// enable run-time checks when not in production | ||
dev: true, | ||
// we'll extract any component CSS out into | ||
// a separate file better for performance | ||
css: css => { | ||
css.write('bundle.css') | ||
} | ||
}), | ||
|
||
// If you have external dependencies installed from | ||
// npm, you'll most likely need these plugins. In | ||
// some cases you'll need additional configuration | ||
// consult the documentation for details: | ||
// https://github.com/rollup/rollup-plugin-commonjs | ||
resolve(), | ||
commonjs() | ||
] | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h1>svelte-spa-router sample</h1> | ||
<h2>Basic routing</h2> | ||
|
||
<!-- Navigation links --> | ||
<ul> | ||
<li><a href="#/">Home</a></li> | ||
<li><a href="#/hello/svelte">Say hi!</a></li> | ||
<li><a href="#/wild/card">Wildcard route</a></li> | ||
<li><a href="#/does/not/exist">Not found</a></li> | ||
</ul> | ||
|
||
<!-- Show the router --> | ||
<Router {routes} /> | ||
|
||
<script> | ||
// Import the router component | ||
// Normally, this would be import: `import Router from 'svelte-spa-router'` | ||
import Router from '../../../Router.svelte' | ||
// Import the list of routes | ||
import routes from './routes' | ||
</script> |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Initialize the Svelte app and inject it in the DOM | ||
import App from './App.svelte' | ||
const app = new App({ | ||
target: document.body | ||
}) | ||
|
||
export default app |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Components | ||
import Home from './routes/Home.svelte' | ||
import Name from './routes/Name.svelte' | ||
import Wild from './routes/Wild.svelte' | ||
import NotFound from './routes/NotFound.svelte' | ||
|
||
// Export the route definition object | ||
export default { | ||
// Exact path | ||
'/': Home, | ||
|
||
// Using named parameters, with last being optional | ||
'/hello/:first/:last?': Name, | ||
|
||
// Wildcard parameter | ||
// Included twice to match both `/wild` (and nothing after) and `/wild/*` (with anything after) | ||
'/wild': Wild, | ||
'/wild/*': Wild, | ||
|
||
// Catch-all, must be last | ||
'*': NotFound, | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h2>Home component</h2> | ||
|
||
<p> | ||
This sample shows how to set up the router with minimum functionality. <br/> | ||
The route definition object contains a number of routes (including some with parameters and a catch-all at the end).<br/> | ||
The links below allow navigating between pages. | ||
</p> | ||
|
||
<p>This is the Home component, which contains markup only.</p> | ||
|
||
<p><em>Hint:</em> Try navigating with the links below, then use your browser's back and forward buttons.</p> |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h2>Hi there!</h2> | ||
|
||
<p> | ||
Your name is: | ||
<b>{params.first}</b> | ||
<b>{#if params.last}{params.last}{/if}</b> | ||
</p> | ||
<p>This comes from the URL, matching <code>/hello/:first/:last?</code>, where the last name is optional.</p> | ||
<p><em>Hint:</em> Try changing the URL and add your name, e.g. <code>/hello/alex</code> or <code>/hello/jane/doe</code></p> | ||
|
||
<script> | ||
// The params prop contains values matched from the URL | ||
export let params = {} | ||
</script> |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h2>NotFound</h2> | ||
|
||
<p>Oops, this route doesn't exist!</p> |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h2>Wildcard</h2> | ||
|
||
<p>Anything in the URL after <code>/wild/</code> is shown below as message. That's found in the <code>params.wild</code> prop.</p> | ||
|
||
<p>Your message is: {params.wild}</p> | ||
|
||
<script> | ||
// The params prop contains values matched from the URL | ||
export let params = {} | ||
</script> |