Skip to content

Commit

Permalink
Fixed types and definePageMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarciaesgi committed Feb 10, 2023
1 parent 15c607a commit 5070b84
Show file tree
Hide file tree
Showing 24 changed files with 1,084 additions and 68 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
Can be disabled with the `experimentalPathCheck` option.

- Autocomplete for path programmatic navigation
- Throw an error if the path doesn't match any defined routes
- Report human readable errors instead of cryptic TS errors
- Support `NuxtLink`, `useRouter`, `navigateTo` and `useLocalePath`
- Support query params and hashs
- Throw an error if the path doesn't match any defined routes pattern

This feature is still experimental and has to be well tested on apps before making it default
This feature is still experimental and has to be well tested on more apps.

## Nuxt devtools support
## Nuxt devtools support ⚙️

- Display Nuxt typed router docs from devtools
- Display nuxt-typed-router docs from devtools

## `definePageMeta` support

Get autocompletion et type check for `redirect`, `validate` and `key`

# Breaking changes ⚠️

Expand Down
1 change: 0 additions & 1 deletion main.d.ts

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Provide autocompletion for pages route names generated by Nuxt router",
"type": "module",
"main": "./dist/module.cjs",
"types": "./main.d.ts",
"types": "./dist/typed.d.ts",
"exports": {
".": {
"import": "./dist/module.mjs",
Expand All @@ -26,9 +26,11 @@
"test:types": "pnpm run typecheck && pnpm run test:vue",
"test:vue": "vue-tsc -p test/fixtures/simple/tsconfig.json --noEmit && vue-tsc -p test/fixtures/complex/tsconfig.json --noEmit && vue-tsc -p test/fixtures/withOptions/tsconfig.json --noEmit",
"test": "pnpm run dev:prepare && pnpm run test:types && pnpm run test:fixtures",
"lint": "eslint --ext .ts --ext .vue .",
"docs:dev": "cd docs && pnpm run dev",
"docs:build": "npm run dev:prepare && cd docs && nuxi generate",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"release": "pnpm test && standard-version && git push --follow-tags && npm publish"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -88,6 +90,7 @@
"eslint-plugin-vue": "^9.9.0",
"nuxt": "3.2.0",
"playwright": "1.30.0",
"standard-version": "^9.5.0",
"tsd": "^0.25.0",
"typescript": "^4.9.5",
"vitest": "^0.28.2",
Expand Down
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineNuxtConfig({
plugin: true,
experimentalPathCheck: true,
},
imports: {},
srcDir: './src',
i18n: {
// add `vueI18n` option to `@nuxtjs/i18n` module options
Expand Down
22 changes: 21 additions & 1 deletion playground/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
<div>
<button @click="navigate"> Navigate button </button>
<nuxt-link :to="{ name: 'admin-id', params: { id: 1 } }">Navigate Link</nuxt-link>
<nuxt-link to="/user/:id/">Navigate Link</nuxt-link>
<nuxt-link to="/admin/:id/foo">Navigate Link</nuxt-link>
<nuxt-link :to="localePath('/admin/:id')">Navigate Link</nuxt-link>
</div>
</template>

<script setup lang="ts">
import { GlobalComponents } from 'vue';
import { PageMeta } from '#app';
import { definePageMeta, TypedRouteLocationRawFromName } from '@typed-router';
definePageMeta({
validate(route) {
return route.name === 'index';
},
redirect(route) {
return { name: 'admin-id', params: { id: 1 } };
},
});
const t = 'zfef';
const u = 'krzfzlkj' as string;
type test<T> = string extends T ? true : false;
type foo = test<typeof u>;
const router = useRouter();
const localePath = useLocalePath();
Expand Down
Loading

0 comments on commit 5070b84

Please sign in to comment.