nuxt-typed-router 1.2.0 → 1.2.3-beta.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 +3 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +15 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,10 +57,8 @@ npm install -D nuxt-typed-router@legacy
|
|
|
57
57
|
First, register the module in the `nuxt.config.ts`
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
|
-
import TypedRouter from 'nuxt-typed-router';
|
|
61
|
-
|
|
62
60
|
export default defineNuxtConfig({
|
|
63
|
-
buildModules: [
|
|
61
|
+
buildModules: ['nuxt-typed-router'],
|
|
64
62
|
nuxtTypedRouter: {
|
|
65
63
|
// options
|
|
66
64
|
},
|
|
@@ -101,10 +99,8 @@ The module will generate 4 files each time you modify the `pages` folder :
|
|
|
101
99
|
You can specify the output dir of the generated files in your configuration. It defaults to `<srcDir>/generated`
|
|
102
100
|
|
|
103
101
|
```ts
|
|
104
|
-
import TypedRouter from 'nuxt-typed-router';
|
|
105
|
-
|
|
106
102
|
export default defineNuxtConfig({
|
|
107
|
-
buildModules: [
|
|
103
|
+
buildModules: ['nuxt-typed-router'],
|
|
108
104
|
nuxtTypedRouter: {
|
|
109
105
|
outDir: './generated',
|
|
110
106
|
},
|
|
@@ -194,6 +190,7 @@ It's available anywhere you have access to Nuxt context
|
|
|
194
190
|
```vue
|
|
195
191
|
<script lang="ts">
|
|
196
192
|
import { defineComponent } from 'vue';
|
|
193
|
+
import { useNuxtApp } from '#app';
|
|
197
194
|
|
|
198
195
|
export default defineComponent({
|
|
199
196
|
name: 'Index',
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extendPages, defineNuxtModule } from '@nuxt/kit';
|
|
1
|
+
import { extendPages, addPluginTemplate, defineNuxtModule } from '@nuxt/kit';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import logSymbols from 'log-symbols';
|
|
4
4
|
import prettier from 'prettier';
|
|
@@ -300,7 +300,7 @@ function createRuntimePluginFile(routesDeclTemplate) {
|
|
|
300
300
|
return {
|
|
301
301
|
provide: {
|
|
302
302
|
typedRouter: nuxtApp.$router,
|
|
303
|
-
routesList,
|
|
303
|
+
routesList: 'prout',
|
|
304
304
|
},
|
|
305
305
|
};
|
|
306
306
|
});
|
|
@@ -390,10 +390,14 @@ function routeHook(outDir, routesObjectName, srcDir, nuxt) {
|
|
|
390
390
|
extendPages(async (routes) => {
|
|
391
391
|
if (routes.length) {
|
|
392
392
|
const { routesDeclTemplate, routesList, routesObjectTemplate, routesParams } = constructRouteMap(routes);
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
|
|
393
|
+
nuxt.hook("build:done", () => {
|
|
394
|
+
const pluginName = "typed-router.mjs";
|
|
395
|
+
const plugin = addPluginTemplate({
|
|
396
|
+
filename: pluginName,
|
|
397
|
+
write: true,
|
|
398
|
+
getContents: () => createRuntimePluginFile(routesDeclTemplate)
|
|
399
|
+
});
|
|
400
|
+
console.log(plugin);
|
|
397
401
|
});
|
|
398
402
|
await Promise.all([
|
|
399
403
|
saveRouteFiles(outDir, srcDir, "__useTypedRouter.ts", createRuntimeHookFile(routesDeclTemplate)),
|
|
@@ -417,9 +421,13 @@ const module = defineNuxtModule({
|
|
|
417
421
|
configKey: "nuxtTypedRouter",
|
|
418
422
|
compatibility: { nuxt: "^3.0.0-rc.1", bridge: false }
|
|
419
423
|
},
|
|
424
|
+
defaults: {
|
|
425
|
+
outDir: `./generated`,
|
|
426
|
+
routesObjectName: "routerPagesNames"
|
|
427
|
+
},
|
|
420
428
|
setup(moduleOptions, nuxt) {
|
|
421
429
|
const srcDir = nuxt.options.srcDir;
|
|
422
|
-
const { outDir
|
|
430
|
+
const { outDir, routesObjectName } = moduleOptions;
|
|
423
431
|
nuxt.hook("pages:extend", () => routeHook(outDir, routesObjectName, srcDir, nuxt));
|
|
424
432
|
routeHook(outDir, routesObjectName, srcDir, nuxt);
|
|
425
433
|
}
|