nuxt-typed-router 1.0.1 → 1.0.2
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 +8 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +17 -1
- package/dist/runtime/typed-router.d.ts +30 -16
- package/dist/runtime/typed-router.mjs +30 -16
- package/dist/runtime/useTypedRouter.d.ts +23 -1
- package/dist/runtime/useTypedRouter.mjs +23 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# 🚗🚦 Nuxt
|
|
1
|
+
# 🚗🚦 Typed Router for Nuxt 3
|
|
2
2
|
|
|
3
3
|
[npm-version-src]: https://img.shields.io/npm/v/nuxt-typed-router.svg
|
|
4
4
|
[npm-version-href]: https://www.npmjs.com/package/nuxt-typed-router
|
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
- 🚚 Expose a global method `$typedRouter` (clone of vue-router), but typed with the routes defined in `pages` directory
|
|
18
18
|
- 🚦 Provides auto-completion and errors for route params in `push` and `replace` methods
|
|
19
19
|
|
|
20
|
+
<br/>
|
|
21
|
+
<br/>
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img src="https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/medias/in-action.gif?raw=true"/>
|
|
24
|
+
</p>
|
|
25
|
+
<br/>
|
|
26
|
+
|
|
20
27
|
# Installation
|
|
21
28
|
|
|
22
29
|
### For Nuxt 3
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -298,6 +298,22 @@ const staticDeclarations = `
|
|
|
298
298
|
}
|
|
299
299
|
`;
|
|
300
300
|
|
|
301
|
+
function createRuntimePluginFile(routesDeclTemplate) {
|
|
302
|
+
return `
|
|
303
|
+
import { defineNuxtPlugin } from '#app';
|
|
304
|
+
|
|
305
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
306
|
+
const routesList = ${routesDeclTemplate};
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
provide: {
|
|
310
|
+
typedRouter: nuxtApp.vueApp.$router,
|
|
311
|
+
routesList,
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
`;
|
|
316
|
+
}
|
|
301
317
|
function createRuntimeHookFile(routesDeclTemplate) {
|
|
302
318
|
return `
|
|
303
319
|
import { getCurrentInstance } from 'vue';
|
|
@@ -373,7 +389,7 @@ function routeHook(outDir, routesObjectName) {
|
|
|
373
389
|
const pluginPath = resolve(runtimeDir, pluginName);
|
|
374
390
|
await Promise.all([
|
|
375
391
|
saveRouteFiles(runtimeDir, "useTypedRouter.mjs", createRuntimeHookFile(routesDeclTemplate)),
|
|
376
|
-
saveRouteFiles(runtimeDir, pluginName,
|
|
392
|
+
saveRouteFiles(runtimeDir, pluginName, createRuntimePluginFile(routesDeclTemplate))
|
|
377
393
|
]);
|
|
378
394
|
addPluginTemplate({
|
|
379
395
|
src: pluginPath,
|
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineNuxtPlugin } from '#app';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
+
const routesList = {
|
|
5
|
+
activate: 'activate',
|
|
6
|
+
index: 'index',
|
|
7
|
+
childOne: {
|
|
8
|
+
childOneChildOneSubOne: 'parent-child-one-child-one-sub-one',
|
|
9
|
+
user: { index: 'parent-child-one-child-one-sub-one-user' },
|
|
10
|
+
childOneChildOneSubTwo: 'parent-child-one-child-one-sub-two',
|
|
11
|
+
index: 'parent-child-one',
|
|
12
|
+
},
|
|
13
|
+
childTwo: {
|
|
14
|
+
childTwoId: 'parent-child-two-id',
|
|
15
|
+
childTwoChildOneSubOne: 'parent-child-two-child-one-sub-one',
|
|
16
|
+
index: 'parent-child-two',
|
|
17
|
+
profile: {
|
|
18
|
+
id: {
|
|
19
|
+
slug: { index: 'parent-child-two-profile-id-slug' },
|
|
20
|
+
index: 'parent-child-two-profile-id',
|
|
21
|
+
},
|
|
22
|
+
index: 'parent-child-two-profile',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
rootPage: 'rootPage',
|
|
26
|
+
};
|
|
15
27
|
|
|
16
28
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
provide: {
|
|
30
|
+
typedRouter: nuxtApp.vueApp.$router,
|
|
31
|
+
routesList,
|
|
32
|
+
},
|
|
19
33
|
};
|
|
20
|
-
};
|
|
34
|
+
});
|
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineNuxtPlugin } from '#app';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
+
const routesList = {
|
|
5
|
+
activate: 'activate',
|
|
6
|
+
index: 'index',
|
|
7
|
+
childOne: {
|
|
8
|
+
childOneChildOneSubOne: 'parent-child-one-child-one-sub-one',
|
|
9
|
+
user: { index: 'parent-child-one-child-one-sub-one-user' },
|
|
10
|
+
childOneChildOneSubTwo: 'parent-child-one-child-one-sub-two',
|
|
11
|
+
index: 'parent-child-one',
|
|
12
|
+
},
|
|
13
|
+
childTwo: {
|
|
14
|
+
childTwoId: 'parent-child-two-id',
|
|
15
|
+
childTwoChildOneSubOne: 'parent-child-two-child-one-sub-one',
|
|
16
|
+
index: 'parent-child-two',
|
|
17
|
+
profile: {
|
|
18
|
+
id: {
|
|
19
|
+
slug: { index: 'parent-child-two-profile-id-slug' },
|
|
20
|
+
index: 'parent-child-two-profile-id',
|
|
21
|
+
},
|
|
22
|
+
index: 'parent-child-two-profile',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
rootPage: 'rootPage',
|
|
26
|
+
};
|
|
15
27
|
|
|
16
28
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
provide: {
|
|
30
|
+
typedRouter: nuxtApp.vueApp.$router,
|
|
31
|
+
routesList,
|
|
32
|
+
},
|
|
19
33
|
};
|
|
20
|
-
};
|
|
34
|
+
});
|
|
@@ -11,7 +11,29 @@ function useNuxtApp() {
|
|
|
11
11
|
export const useTypedRouter = () => {
|
|
12
12
|
const { $router } = useNuxtApp();
|
|
13
13
|
|
|
14
|
-
const routesList = {
|
|
14
|
+
const routesList = {
|
|
15
|
+
activate: 'activate',
|
|
16
|
+
index: 'index',
|
|
17
|
+
childOne: {
|
|
18
|
+
childOneChildOneSubOne: 'parent-child-one-child-one-sub-one',
|
|
19
|
+
user: { index: 'parent-child-one-child-one-sub-one-user' },
|
|
20
|
+
childOneChildOneSubTwo: 'parent-child-one-child-one-sub-two',
|
|
21
|
+
index: 'parent-child-one',
|
|
22
|
+
},
|
|
23
|
+
childTwo: {
|
|
24
|
+
childTwoId: 'parent-child-two-id',
|
|
25
|
+
childTwoChildOneSubOne: 'parent-child-two-child-one-sub-one',
|
|
26
|
+
index: 'parent-child-two',
|
|
27
|
+
profile: {
|
|
28
|
+
id: {
|
|
29
|
+
slug: { index: 'parent-child-two-profile-id-slug' },
|
|
30
|
+
index: 'parent-child-two-profile-id',
|
|
31
|
+
},
|
|
32
|
+
index: 'parent-child-two-profile',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
rootPage: 'rootPage',
|
|
36
|
+
};
|
|
15
37
|
|
|
16
38
|
return {
|
|
17
39
|
router: $router,
|
|
@@ -11,7 +11,29 @@ function useNuxtApp() {
|
|
|
11
11
|
export const useTypedRouter = () => {
|
|
12
12
|
const { $router } = useNuxtApp();
|
|
13
13
|
|
|
14
|
-
const routesList = {
|
|
14
|
+
const routesList = {
|
|
15
|
+
activate: 'activate',
|
|
16
|
+
index: 'index',
|
|
17
|
+
childOne: {
|
|
18
|
+
childOneChildOneSubOne: 'parent-child-one-child-one-sub-one',
|
|
19
|
+
user: { index: 'parent-child-one-child-one-sub-one-user' },
|
|
20
|
+
childOneChildOneSubTwo: 'parent-child-one-child-one-sub-two',
|
|
21
|
+
index: 'parent-child-one',
|
|
22
|
+
},
|
|
23
|
+
childTwo: {
|
|
24
|
+
childTwoId: 'parent-child-two-id',
|
|
25
|
+
childTwoChildOneSubOne: 'parent-child-two-child-one-sub-one',
|
|
26
|
+
index: 'parent-child-two',
|
|
27
|
+
profile: {
|
|
28
|
+
id: {
|
|
29
|
+
slug: { index: 'parent-child-two-profile-id-slug' },
|
|
30
|
+
index: 'parent-child-two-profile-id',
|
|
31
|
+
},
|
|
32
|
+
index: 'parent-child-two-profile',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
rootPage: 'rootPage',
|
|
36
|
+
};
|
|
15
37
|
|
|
16
38
|
return {
|
|
17
39
|
router: $router,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-typed-router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Provide autocompletion for pages route names generated by Nuxt router",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"play:build": "nuxi build playground",
|
|
9
9
|
"prepack": "nuxt-module-build",
|
|
10
10
|
"build:local": "nuxt-module-build --stub && cross-env NUXT_BUILD_TYPE=stub nuxi dev playground",
|
|
11
|
-
"
|
|
11
|
+
"init:build": "nuxt-module-build --stub && nuxi prepare playground",
|
|
12
|
+
"build:test": "cross-env NUXT_BUILD_TYPE=stub yarn init:build && yarn prepack && yarn play:build",
|
|
13
|
+
"test": "yarn build:test && jest",
|
|
12
14
|
"test:reset": "yarn test --updateSnapshot"
|
|
13
15
|
},
|
|
14
16
|
"exports": {
|