Skip to content

Commit

Permalink
Merge pull request #128 from victorgarciaesgi/feat/3.4.0
Browse files Browse the repository at this point in the history
v3.4.0
  • Loading branch information
victorgarciaesgi committed Nov 27, 2023
2 parents cc72b45 + 35b2522 commit b37109d
Show file tree
Hide file tree
Showing 29 changed files with 4,793 additions and 9,031 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ Demo repo 🧪 : [nuxt-typed-router-demo](https://github.com/victorgarciaesgi/nu
# Compatibility:

- Nuxt 3
- Nuxt 2 (via [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2))



# Quick start
Expand All @@ -76,16 +74,6 @@ npm install -D nuxt-typed-router
pnpm install -D nuxt-typed-router
```

### Nuxt 2 legacy (not maintained)

Nuxt 2 version is no longer maintained, but still available in [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2)
It only has route name autocomplete functionnality

```bash
yarn add -D nuxt-typed-router@legacy
# or
npm install -D nuxt-typed-router@legacy
```

# Configuration
Register the module in the `nuxt.config.ts`, done!
Expand Down
56 changes: 56 additions & 0 deletions docs/content/2.usage/8.typing-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Typing component props
---

# NuxtLink


Sometimes you don't want to use `NuxtLink` directly and make a wrapper component, there is a way to do it with `nuxt-typed-router`. It implies using component generics if you're on a Vue SFC

```vue
<template>
<NuxtLink :to="props.to"></NuxtLink>
</template>
<script setup lang="ts" generic="T extends RoutesNamesList, P extends string">
import type { RoutesNamesList, NuxtRoute } from '@typed-router';
const props = defineProps<{
to: NuxtRoute<T, P>;
}>();
</script>
```

It's also easy to add support for `external` prop

```vue
<template>
<NuxtLink :to="props.to" :external='props.external'></NuxtLink>
</template>
<script setup lang="ts" generic="T extends RoutesNamesList, P extends string, E extends boolean = false">
import type { RoutesNamesList, NuxtRoute } from '@typed-router';
const props = defineProps<{
to: NuxtRoute<T, P>,
external?: E,
}>();
</script>
```

## Same behaviour for pure Typescript functions


```ts
import type { RoutesNamesList, NuxtRoute } from '@typed-router';

export function myCustomNavigateTool<T extends RoutesNamesList, P extends string>(to: NuxtRoute<T, P>) {
//
}

```


::alert{type="info"}
There is also the same type variant if you use `@nuxtjs/i18n` : `NuxtLocaleRoute`
::
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: experimentalRemoveNuxtDefs
title: removeNuxtDefs
---

# experimentalRemoveNuxtDefs
# removeNuxtDefs

Remove Nuxt global definitions for `useRouter` etc.. to avoid conflicts
## Type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
title: experimentalIgnoreRoutes
title: ignoreRoutes
---

# experimentalIgnoreRoutes
# ignoreRoutes

Allow to ignore selected files to be typed, for exemple 404 routes or catch-all routes.
You can pass an array of file paths (taking base of your `pagesDir`).

Usage:

```ts
experimentalIgnoreRoutes: ["[...404].vue", "admin/[...slug].vue"];
ignoreRoutes: ["[...404].vue", "admin/[...slug].vue"];
```

## Type
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"@nuxt-themes/docus": "1.14.3",
"nuxt": "^3.8.1"
"nuxt": "3.8.1"
}
}

0 comments on commit b37109d

Please sign in to comment.