svelte-spa-history-router 2.2.0-next.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -6
- package/examples/app-svelte4/package-lock.json +295 -226
- package/examples/app-svelte4/package.json +5 -5
- package/examples/app-svelte5/package-lock.json +404 -329
- package/examples/app-svelte5/package.json +4 -5
- package/package.json +3 -3
- package/examples/app-svelte5/dist/assets/Admin-DoyP5Bto.js +0 -1
- package/examples/app-svelte5/dist/assets/Blog-seinfUgf.js +0 -1
- package/examples/app-svelte5/dist/assets/Post-DkdqlSq4.js +0 -1
- package/examples/app-svelte5/dist/assets/index-ADyOUHdb.js +0 -2
- package/examples/app-svelte5/dist/index.html +0 -14
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# svelte-spa-history-router
|
|
2
2
|
|
|
3
|
-
History base router for Svelte
|
|
3
|
+
History base router for [Svelte](https://svelte.dev/) SPA (Single Page Application).
|
|
4
|
+
|
|
5
|
+
> [!TIP]
|
|
6
|
+
> The offcial routing library of Svelte is [SvelteKit](https://svelte.dev/docs/kit/introduction). This library is intented to be used for small project.
|
|
7
|
+
|
|
4
8
|
|
|
5
9
|
## Features
|
|
6
10
|
|
|
@@ -58,13 +62,28 @@ For example:
|
|
|
58
62
|
|
|
59
63
|
### routeParams
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
Matched paramaters is passed to component as `params` property.
|
|
62
66
|
|
|
63
67
|
For example:
|
|
64
68
|
|
|
65
69
|
```html
|
|
66
70
|
# Article.svelte
|
|
67
71
|
|
|
72
|
+
<script lang="ts">
|
|
73
|
+
let { params } = $props();
|
|
74
|
+
|
|
75
|
+
const postId = $derived(parseInt(params.postId));
|
|
76
|
+
</script>
|
|
77
|
+
<div>
|
|
78
|
+
{ postId }
|
|
79
|
+
</div>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
[Additional] For svelte4, `routeParams` is a store to contain matched value to current route.
|
|
83
|
+
|
|
84
|
+
```html
|
|
85
|
+
# Article.svelte
|
|
86
|
+
|
|
68
87
|
<script>
|
|
69
88
|
import { routeParams } from 'svelte-spa-history-router';
|
|
70
89
|
</script>
|
|
@@ -105,7 +124,7 @@ Example: code spliting (dynamic import)
|
|
|
105
124
|
import { Router } from 'svelte-spa-history-router';
|
|
106
125
|
|
|
107
126
|
const routes = [
|
|
108
|
-
{ path: '/', resolver:
|
|
127
|
+
{ path: '/', resolver: () => import("Home.svelte") },
|
|
109
128
|
];
|
|
110
129
|
</script>
|
|
111
130
|
<Router {routes}/>
|
|
@@ -120,11 +139,11 @@ Example: dynamic routing and pass value to component props.
|
|
|
120
139
|
import Article from "./Article.svelte";
|
|
121
140
|
import NotFound from "./NotFound.svelte";
|
|
122
141
|
|
|
123
|
-
async function prefetchArticle(
|
|
124
|
-
const article = await getArticle(
|
|
142
|
+
async function prefetchArticle({ params, props }) {
|
|
143
|
+
const article = await getArticle(params.postId);
|
|
125
144
|
if (article) {
|
|
126
145
|
// pass value to component props
|
|
127
|
-
|
|
146
|
+
props.article = article;
|
|
128
147
|
return Article;
|
|
129
148
|
} else {
|
|
130
149
|
return NotFound;
|
|
@@ -184,6 +203,10 @@ store to detect URL changes (including query string or hash)
|
|
|
184
203
|
|
|
185
204
|
## ChangeLog
|
|
186
205
|
|
|
206
|
+
### 2.2.0
|
|
207
|
+
|
|
208
|
+
* Support Svelte5
|
|
209
|
+
|
|
187
210
|
### 2.2.0-next.1
|
|
188
211
|
|
|
189
212
|
* Fix component type on svelte5 [PR13](https://github.com/ykrods/svelte-spa-history-router/pull/13)
|