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 CHANGED
@@ -1,7 +1,7 @@
1
- # ๐Ÿš—๐Ÿšฆ Typed Router for Nuxt
1
+
2
2
 
3
3
  <p align="center">
4
- <img width='100' src="https://raw.githubusercontent.com/victorgarciaesgi/nuxt-typed-router/master/.github/images/logo.png" alt="nuxt-typed-router logo">
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
- - ๐ŸŽ Provides a hook `useTypedRouter` that returns an alias of `$typedRouter` and also a typed list of your routes
22
- - ๐Ÿšš Expose a global method `$typedRouter` (clone of vue-router), but typed with the routes defined in `pages` directory
23
- - ๐Ÿšฆ Provides auto-completion and errors for route params in `push` and `replace` methods
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
+ [![Open in StackBlitz](https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/.github/images/redirectDoc.svg?raw=true)](https://nuxt-typed-router.vercel.app/)
39
+
40
+ # Play with it
41
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](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
- ## Compatibility:
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
- # Installation
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
- # Quick start
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
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0-rc.1",
6
6
  "bridge": false
7
7
  },
8
- "version": "2.0.0-beta.1"
8
+ "version": "2.0.0"
9
9
  }
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
- ${params.map(({ key, type }) => `"${key}": ${type}`).join(",\n")}
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, required: !optional });
462
+ params.push({ name: key, optional: !!optional });
461
463
  }
462
464
  }
463
465
  } while (matches);
464
466
  let allMergedParams = params.map(
465
- ({ name, required }) => ({
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-beta.1",
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:buid": "(cd docs && nuxi build)"
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"