Skip to content

Commit

Permalink
docs: example with layouts
Browse files Browse the repository at this point in the history
Close #15
  • Loading branch information
posva committed Jul 5, 2022
1 parent 76beb8a commit 8322d6c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ createRouter({
})
```

Make sure to also check [the TypeScript section](#typescript) below if you are using TypeScript.
Make sure to also check and follow [the TypeScript section](#typescript) below **if you are using TypeScript or have a `jsconfig.json` file**.

## Configuration

Expand Down Expand Up @@ -247,7 +247,7 @@ To create a catch all route prepend 3 dots (`...`) to the param name, e.g. `src/

## TypeScript

This plugin generates a `d.ts` file with all the typing overrides when the dev or build server is ran. Make sure to include it in your `tsconfig.json`'s `include` or `files` property:
This plugin generates a `d.ts` file with all the typing overrides when the dev or build server is ran. Make sure to include it in your `tsconfig.json`'s (or `jsconfig.json`'s) `include` or `files` property:

```js
{
Expand Down Expand Up @@ -362,6 +362,18 @@ const router = createRouter({
As this plugin evolves, this function should be used less and less and only become necessary in unique edge cases.
One example of this is using [vite-plugin-vue-layouts](https://github.com/JohnCampionJr/vite-plugin-vue-layouts) which can only be used alongside `extendRoutes()`:
```ts
import { createRouter } from '@vue-router'
import { setupLayouts } from 'virtual:generated-layouts'

const router = createRouter({
// ...
extendRoutes: (routes) => setupLayouts(routes),
})
```
## Rationale
This project idea came from trying [to type the router directly using Typescript](https://github.com/vuejs/router/pull/1397/commits/c577998f3edaa6a1eb9474c27ab6c58f6e2d7c8a), finding out it's not fast enough to be pleasant to use and, ending up using build-based tools, taking some inspiration from other projects like:
Expand Down

0 comments on commit 8322d6c

Please sign in to comment.