nuxt-typed-router 2.0.0-beta.1 โ 2.0.1
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 +11 -8
- package/package.json +7 -6
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
|
@@ -171,7 +171,8 @@ function createDeclarationRoutesFile() {
|
|
|
171
171
|
function createRuntimeIndexFile() {
|
|
172
172
|
return `
|
|
173
173
|
${watermarkTemplate}
|
|
174
|
-
export {routesNames
|
|
174
|
+
export { routesNames } from './__routes';
|
|
175
|
+
export type { TypedRouteList } from './__routes';
|
|
175
176
|
export * from './__useTypedRouter';
|
|
176
177
|
export * from './__useTypedRoute';
|
|
177
178
|
`;
|
|
@@ -205,7 +206,7 @@ function createTypedRouteParamsExport(routesParams) {
|
|
|
205
206
|
return `export type TypedRouteParams = {
|
|
206
207
|
${routesParams.map(
|
|
207
208
|
({ name, params }) => `"${name}": ${params.length ? `{
|
|
208
|
-
${params.map(({ key, required
|
|
209
|
+
${params.map(({ key, required }) => `"${key}"${required ? "" : "?"}: string | number`).join(",\n")}
|
|
209
210
|
}` : "never"}`
|
|
210
211
|
).join(",\n")}
|
|
211
212
|
}`;
|
|
@@ -214,7 +215,7 @@ function createTypedRouteNamedMapperExport(routesParams) {
|
|
|
214
215
|
return `export type TypedRouteNamedMapper =
|
|
215
216
|
${routesParams.map(
|
|
216
217
|
({ name, params }) => `{name: "${name}" ${params.length ? `, params${params.some((s) => s.required) ? "" : "?"}: {
|
|
217
|
-
${params.map(({ key, required
|
|
218
|
+
${params.map(({ key, required }) => `"${key}"${required ? "" : "?"}: string | number`).join(",\n")}
|
|
218
219
|
}` : ""}}`
|
|
219
220
|
).join("|\n")}
|
|
220
221
|
`;
|
|
@@ -227,7 +228,9 @@ function createResolvedTypedRouteNamedMapperExport(routesParams) {
|
|
|
227
228
|
} & (
|
|
228
229
|
${routesParams.map(
|
|
229
230
|
({ name, params }) => `{name: "${name}" ${params.length ? `, params: {
|
|
230
|
-
|
|
231
|
+
${params.map(
|
|
232
|
+
({ key, notRequiredOnPage }) => `"${key}"${notRequiredOnPage ? "?" : ""}: string`
|
|
233
|
+
).join(",\n")}
|
|
231
234
|
}` : ""}}`
|
|
232
235
|
).join("|\n")}
|
|
233
236
|
)
|
|
@@ -457,15 +460,15 @@ function extractRouteParamsFromPath(path, isIndexFileForRouting, previousParams)
|
|
|
457
460
|
if (matches) {
|
|
458
461
|
const [_, mtch, key, optional] = matches;
|
|
459
462
|
if (mtch) {
|
|
460
|
-
params.push({ name: key,
|
|
463
|
+
params.push({ name: key, optional: !!optional });
|
|
461
464
|
}
|
|
462
465
|
}
|
|
463
466
|
} while (matches);
|
|
464
467
|
let allMergedParams = params.map(
|
|
465
|
-
({ name,
|
|
468
|
+
({ name, optional }) => ({
|
|
466
469
|
key: name,
|
|
467
|
-
|
|
468
|
-
|
|
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.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Provide autocompletion for pages route names generated by Nuxt router",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"dev": "nuxi dev playground",
|
|
21
21
|
"dev:build": "nuxi build playground",
|
|
22
22
|
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
|
|
23
|
-
"build:test": "cross-env NUXT_BUILD_TYPE=stub
|
|
24
|
-
"test": "
|
|
25
|
-
"test:watch": "
|
|
26
|
-
"docs:dev": "cd docs &&
|
|
27
|
-
"docs:
|
|
23
|
+
"build:test": "cross-env NUXT_BUILD_TYPE=stub yarn prepack && yarn dev:build",
|
|
24
|
+
"test": "yarn dev:prepare && yarn build:test && vitest run",
|
|
25
|
+
"test:watch": "yarn build:test && vitest",
|
|
26
|
+
"docs:dev": "cd docs && yarn dev",
|
|
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"
|