nuxt-typed-router 2.0.0-beta.1 โ 2.0.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 +30 -16
- package/dist/module.json +1 -1
- package/dist/module.mjs +7 -4
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img
|
|
4
|
+
<img src="https://raw.githubusercontent.com/victorgarciaesgi/nuxt-typed-router/master/.github/images/cover.png" alt="nuxt-typed-router cover">
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
|
|
@@ -18,26 +18,40 @@
|
|
|
18
18
|
|
|
19
19
|
## Provide a type safe router to Nuxt with auto-generated typed definitions for route names and autocompletion for route params
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
21
|
+
- Automaticaly provides types check and autocomplete to `NuxtLink`
|
|
22
|
+
- Exports a `useTypedRouter` and `useTypedRoute` composable
|
|
23
|
+
- Supports routes defined in `config.extendRoutes`
|
|
24
|
+
- Infer route params based on route name
|
|
25
|
+
- Provide global `$typedRouter` util
|
|
26
|
+
|
|
27
|
+
<br/>
|
|
24
28
|
|
|
25
29
|
<br/>
|
|
30
|
+
<p align="center">
|
|
31
|
+
<img src="https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/.github/images/nuxt-router.gif?raw=true"/>
|
|
32
|
+
</p>
|
|
33
|
+
<br/>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Documentation
|
|
37
|
+
|
|
38
|
+
[](https://nuxt-typed-router.vercel.app/)
|
|
39
|
+
|
|
40
|
+
# Play with it
|
|
41
|
+
[](https://stackblitz.com/edit/github-7e4xvw?file=store/testRouter.ts)
|
|
26
42
|
|
|
27
|
-
Demo ๐งช : [nuxt-typed-router-demo](https://github.com/victorgarciaesgi/nuxt-typed-router-demo)
|
|
43
|
+
Demo repo ๐งช : [nuxt-typed-router-demo](https://github.com/victorgarciaesgi/nuxt-typed-router-demo)
|
|
28
44
|
|
|
29
|
-
|
|
45
|
+
<br/>
|
|
46
|
+
|
|
47
|
+
# Compatibility:
|
|
30
48
|
|
|
31
49
|
- Nuxt 3
|
|
32
50
|
- Nuxt 2 (via [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2))
|
|
33
51
|
|
|
34
|
-
<br/>
|
|
35
|
-
<p align="center">
|
|
36
|
-
<img src="https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/.github/images/in-action.gif?raw=true"/>
|
|
37
|
-
</p>
|
|
38
|
-
<br/>
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
|
|
54
|
+
# Quick start
|
|
41
55
|
|
|
42
56
|
### For Nuxt 3
|
|
43
57
|
|
|
@@ -50,6 +64,7 @@ npm install -D nuxt-typed-router
|
|
|
50
64
|
### Nuxt 2 legacy
|
|
51
65
|
|
|
52
66
|
Nuxt 2 version is no longer maintained, but still available in [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2)
|
|
67
|
+
It only has route name autocomplete functionnality
|
|
53
68
|
|
|
54
69
|
```bash
|
|
55
70
|
yarn add -D nuxt-typed-router@legacy
|
|
@@ -57,9 +72,8 @@ yarn add -D nuxt-typed-router@legacy
|
|
|
57
72
|
npm install -D nuxt-typed-router@legacy
|
|
58
73
|
```
|
|
59
74
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
First, register the module in the `nuxt.config.ts`
|
|
75
|
+
# Configuration
|
|
76
|
+
Register the module in the `nuxt.config.ts`, done!
|
|
63
77
|
|
|
64
78
|
```ts
|
|
65
79
|
export default defineNuxtConfig({
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -227,7 +227,9 @@ function createResolvedTypedRouteNamedMapperExport(routesParams) {
|
|
|
227
227
|
} & (
|
|
228
228
|
${routesParams.map(
|
|
229
229
|
({ name, params }) => `{name: "${name}" ${params.length ? `, params: {
|
|
230
|
-
|
|
230
|
+
${params.map(
|
|
231
|
+
({ key, notRequiredOnPage, type }) => `"${key}"${notRequiredOnPage ? "?" : ""}: ${type}`
|
|
232
|
+
).join(",\n")}
|
|
231
233
|
}` : ""}}`
|
|
232
234
|
).join("|\n")}
|
|
233
235
|
)
|
|
@@ -457,15 +459,16 @@ function extractRouteParamsFromPath(path, isIndexFileForRouting, previousParams)
|
|
|
457
459
|
if (matches) {
|
|
458
460
|
const [_, mtch, key, optional] = matches;
|
|
459
461
|
if (mtch) {
|
|
460
|
-
params.push({ name: key,
|
|
462
|
+
params.push({ name: key, optional: !!optional });
|
|
461
463
|
}
|
|
462
464
|
}
|
|
463
465
|
} while (matches);
|
|
464
466
|
let allMergedParams = params.map(
|
|
465
|
-
({ name,
|
|
467
|
+
({ name, optional }) => ({
|
|
466
468
|
key: name,
|
|
467
469
|
type: "string | number",
|
|
468
|
-
required
|
|
470
|
+
required: !optional,
|
|
471
|
+
notRequiredOnPage: optional
|
|
469
472
|
})
|
|
470
473
|
);
|
|
471
474
|
if (previousParams?.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-typed-router",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Provide autocompletion for pages route names generated by Nuxt router",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "pnpm run dev:prepare && pnpm run build:test && vitest run",
|
|
25
25
|
"test:watch": "pnpm run build:test && vitest",
|
|
26
26
|
"docs:dev": "cd docs && pnpm run dev",
|
|
27
|
-
"docs:
|
|
27
|
+
"docs:build": "npm run dev:prepare && cd docs && nuxi generate"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"nuxt 3",
|
|
40
40
|
"nuxt 3 router"
|
|
41
41
|
],
|
|
42
|
+
"homepage": "https://nuxt-typed-router.vercel.app/",
|
|
42
43
|
"repository": {
|
|
43
44
|
"type": "git",
|
|
44
45
|
"url": "git+https://victorgarciaesgi@github.com/victorgarciaesgi/nuxt-typed-router.git"
|