From 75ece5a02e4b45e51ec19a2e3f8f971849824023 Mon Sep 17 00:00:00 2001 From: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Date: Sun, 20 Sep 2020 06:16:18 +0000 Subject: [PATCH] First sample: basic routing --- .eslintignore | 5 ++- .gitignore | 5 +++ README.md | 2 ++ examples/basic-routing/dist/index.html | 13 ++++++++ examples/basic-routing/rollup.config.js | 33 +++++++++++++++++++ examples/basic-routing/src/App.svelte | 22 +++++++++++++ examples/basic-routing/src/main.js | 7 ++++ examples/basic-routing/src/routes.js | 22 +++++++++++++ examples/basic-routing/src/routes/Home.svelte | 11 +++++++ examples/basic-routing/src/routes/Name.svelte | 14 ++++++++ .../basic-routing/src/routes/NotFound.svelte | 3 ++ examples/basic-routing/src/routes/Wild.svelte | 10 ++++++ 12 files changed, 146 insertions(+), 1 deletion(-) create mode 100755 examples/basic-routing/dist/index.html create mode 100755 examples/basic-routing/rollup.config.js create mode 100644 examples/basic-routing/src/App.svelte create mode 100644 examples/basic-routing/src/main.js create mode 100644 examples/basic-routing/src/routes.js create mode 100644 examples/basic-routing/src/routes/Home.svelte create mode 100644 examples/basic-routing/src/routes/Name.svelte create mode 100644 examples/basic-routing/src/routes/NotFound.svelte create mode 100644 examples/basic-routing/src/routes/Wild.svelte diff --git a/.eslintignore b/.eslintignore index 2176928..fed184a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,5 @@ # Test app -test/app \ No newline at end of file +test/app + +# Compiled +examples/*/dist diff --git a/.gitignore b/.gitignore index 6652056..5bb3a7a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ test/app/dist/bundle* test/app/dist/*.js test/app/dist/*.js.map +# Example apps +examples/*/dist/bundle* +examples/*/dist/*.js +examples/*/dist/*.js.map + # This is a module published on NPM, so we can ignore package-lock.json package-lock.json diff --git a/README.md b/README.md index f71d491..174ce2c 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ npm install # Navigate to a sample cd examples/… +# For example +cd examples/basic-routing # Build and run (in the folder of a sample) npx rollup -c diff --git a/examples/basic-routing/dist/index.html b/examples/basic-routing/dist/index.html new file mode 100755 index 0000000..6424790 --- /dev/null +++ b/examples/basic-routing/dist/index.html @@ -0,0 +1,13 @@ + + +
+ + + +
+ This sample shows how to set up the router with minimum functionality.
+ The route definition object contains a number of routes (including some with parameters and a catch-all at the end).
+ The links below allow navigating between pages.
+
This is the Home component, which contains markup only.
+ +Hint: Try navigating with the links below, then use your browser's back and forward buttons.
diff --git a/examples/basic-routing/src/routes/Name.svelte b/examples/basic-routing/src/routes/Name.svelte new file mode 100644 index 0000000..5707e05 --- /dev/null +++ b/examples/basic-routing/src/routes/Name.svelte @@ -0,0 +1,14 @@ ++ Your name is: + {params.first} + {#if params.last}{params.last}{/if} +
+This comes from the URL, matching /hello/:first/:last?
, where the last name is optional.
Hint: Try changing the URL and add your name, e.g. /hello/alex
or /hello/jane/doe
Oops, this route doesn't exist!
diff --git a/examples/basic-routing/src/routes/Wild.svelte b/examples/basic-routing/src/routes/Wild.svelte new file mode 100644 index 0000000..b1c5426 --- /dev/null +++ b/examples/basic-routing/src/routes/Wild.svelte @@ -0,0 +1,10 @@ +Anything in the URL after /wild/
is shown below as message. That's found in the params.wild
prop.
Your message is: {params.wild}
+ +