Skip to content

Commit df872b9

Browse files
committed
chore: playground updates
1 parent 5c1b6c3 commit df872b9

File tree

9 files changed

+44
-41
lines changed

9 files changed

+44
-41
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {
1313
apiIndexFile,
1414
typedRouterFile,
15+
typedRouterFileAsModule,
1516
usersLoaderFile,
1617
vueShimFile,
1718
} from './twoslash-files'
@@ -22,6 +23,7 @@ export default defineConfig({
2223
transformerTwoslash({
2324
twoslashOptions: {
2425
extraFiles: {
26+
'router.ts': typedRouterFileAsModule,
2527
'typed-router.d.ts': typedRouterFile,
2628
'api/index.ts': apiIndexFile,
2729
'../api/index.ts': apiIndexFile,

docs/.vitepress/twoslash-files.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
export const typedRouterFile = `
2+
import type {
3+
RouteRecordInfo,
4+
ParamValue,
5+
ParamValueOneOrMore,
6+
ParamValueZeroOrMore,
7+
ParamValueZeroOrOne,
8+
} from 'vue-router'
9+
210
declare module 'vue-router/auto-routes' {
3-
import type {
4-
RouteRecordInfo,
5-
ParamValue,
6-
ParamValueOneOrMore,
7-
ParamValueZeroOrMore,
8-
ParamValueZeroOrOne,
9-
} from 'unplugin-vue-router/types'
1011
export interface RouteNamedMap {
1112
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>
1213
'/users': RouteRecordInfo<
@@ -30,6 +31,7 @@ declare module 'vue-router/auto-routes' {
3031
}
3132
}
3233
`
34+
export const typedRouterFileAsModule = typedRouterFile + '\nexport {}\n'
3335
export const apiIndexFile = `
3436
export interface User {
3537
id: number

docs/guide/extending-routes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export {}
5353
// ---cut-end---
5454
// @errors: 2322 2339
5555
// @moduleResolution: bundler
56-
import { definePage } from 'vue-router/auto'
56+
import { definePage } from 'unplugin-vue-router/runtime'
5757
5858
definePage({
5959
alias: ['/n/:name'],
@@ -94,7 +94,7 @@ Note you can specify the language to use with `<route lang="yaml">`. By default,
9494
As an escape-hatch, it's possible to extend the routes **at runtime** by simply changing the `routes` array before passing it to `createRouter()`. Since these changes are made at runtime, they are not reflected in the generated `typed-router.d.ts` file.
9595

9696
```js{4-9}
97-
import { createWebHistory, createRouter } from 'vue-router/auto'
97+
import { createWebHistory, createRouter } from 'vue-router'
9898
import { routes } from 'vue-router/auto-routes'
9999
100100
for (const route of routes) {
@@ -115,7 +115,7 @@ As this plugin evolves, this should be used less and less and only become necess
115115
One example of this is using [vite-plugin-vue-layouts](https://github.com/JohnCampionJr/vite-plugin-vue-layouts) which can only be used this way:
116116

117117
```ts
118-
import { createRouter } from 'vue-router/auto'
118+
import { createRouter } from 'vue-router'
119119
import { routes } from 'vue-router/auto-routes'
120120
import { setupLayouts } from 'virtual:generated-layouts'
121121

docs/guide/typescript.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ You can commit the newly added `.d.ts` files to your repository to make your lif
2424
import 'unplugin-vue-router/client'
2525
import './typed-router.d'
2626
// ---cut-end---
27-
// @errors: 2322 2339
2827
// @moduleResolution: bundler
29-
import { useRouter, useRoute } from 'vue-router/auto'
28+
import { useRouter, useRoute } from 'vue-router'
3029
const router = useRouter()
3130
router.push('')
3231
// ^|
@@ -48,16 +47,15 @@ Extending types with dynamically added routes:
4847

4948
```ts
5049
export {} // needed in .d.ts files
50+
import type {
51+
RouteRecordInfo,
52+
ParamValue,
53+
// these are other param helper types
54+
ParamValueOneOrMore,
55+
ParamValueZeroOrMore,
56+
ParamValueZeroOrOne,
57+
} from 'vue-router'
5158
declare module 'vue-router/auto-routes' {
52-
import type {
53-
RouteRecordInfo,
54-
ParamValue,
55-
// these are other param helper types
56-
ParamValueOneOrMore,
57-
ParamValueZeroOrMore,
58-
ParamValueZeroOrOne,
59-
} from 'unplugin-vue-router/types'
60-
6159
export interface RouteNamedMap {
6260
// the key is the name and should match the first generic of RouteRecordInfo
6361
'custom-dynamic-name': RouteRecordInfo<
@@ -77,7 +75,7 @@ declare module 'vue-router/auto-routes' {
7775
The `Router` type gives you access to the typed version of the router instance. It's also the _ReturnType_ of the `useRouter()` function.
7876

7977
```ts
80-
import type { Router } from 'vue-router/auto'
78+
import type { Router } from 'vue-router'
8179
```
8280

8381
### `RouteLocationResolved`
@@ -98,7 +96,7 @@ You have the same equivalents for `RouteLocation`, `RouteLocationNormalized`, an
9896
// ---cut-start---
9997
import 'unplugin-vue-router/client'
10098
import './typed-router.d'
101-
import { useRoute, type RouteLocationNormalizedLoaded } from 'vue-router/auto'
99+
import { useRoute, type RouteLocationNormalizedLoaded } from 'vue-router'
102100
// ---cut-end---
103101
// @errors: 2322 2339
104102
// @moduleResolution: bundler

docs/introduction.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ After adding this plugin, **start the dev server** (usually `npm run dev`) **to
102102
// It's recommended to commit this file.
103103
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.
104104

105-
declare module 'vue-router/auto-routes' {
106-
import type {
107-
RouteRecordInfo,
108-
ParamValue,
109-
ParamValueOneOrMore,
110-
ParamValueZeroOrMore,
111-
ParamValueZeroOrOne,
112-
} from 'unplugin-vue-router/types'
105+
import type {
106+
RouteRecordInfo,
107+
ParamValue,
108+
ParamValueOneOrMore,
109+
ParamValueZeroOrMore,
110+
ParamValueZeroOrOne,
111+
} from 'vue-router'
113112

113+
declare module 'vue-router/auto-routes' {
114114
/**
115115
* Route name map generated by unplugin-vue-router
116116
*/
@@ -177,8 +177,7 @@ Given the following route configuration:
177177
::: code-group
178178

179179
```ts [src/router.ts]
180-
import { createRouter, createWebHistory } from 'vue-router' // [!code --]
181-
import { createRouter, createWebHistory } from 'vue-router/auto' // [!code ++]
180+
import { createRouter, createWebHistory } from 'vue-router'
182181
import { routes } from 'vue-router/auto-routes' // [!code ++]
183182
184183
export const router = createRouter({
@@ -226,7 +225,7 @@ Check the [file-based routing](/guide/file-based-routing) guide for more informa
226225

227226
```ts{2-3,6-9,12} [src/main.ts]
228227
import { createApp } from 'vue'
229-
import { createRouter, createWebHistory } from 'vue-router/auto'
228+
import { createRouter, createWebHistory } from 'vue-router'
230229
import { routes } from 'vue-router/auto-routes'
231230
import App from './App.vue'
232231
@@ -309,6 +308,8 @@ export default defineConfig({
309308
})
310309
```
311310

311+
FIXME: DELETE
312+
312313
Note that the `vue-router` preset might export less things than the one exported by `unplugin-vue-router` so you might need to add any other imports you were relying on manually:
313314

314315
```ts

docs/rfcs/data-loaders/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ You might only be interested in trying out Data Loaders. In that case, check out
202202

203203
```ts{2,9}
204204
import { createApp } from 'vue'
205-
import { DataLoaderPlugin, createRouter } from 'vue-router/auto'
205+
import { createRouter } from 'vue-router'
206+
import { DataLoaderPlugin } from 'vue-router/auto'
206207
207208
const router = createRouter({
208209
// ...
@@ -562,7 +563,8 @@ Since navigation loaders can run in parallel, they can return different navigati
562563
```ts{3-6} twoslash
563564
import 'unplugin-vue-router/client'
564565
import { createApp } from 'vue'
565-
import { DataLoaderPlugin, createRouter, createWebHistory } from 'vue-router/auto'
566+
import { createRouter, createWebHistory } from 'vue-router'
567+
import { DataLoaderPlugin } from 'vue-router/auto'
566568
const app = createApp({})
567569
const router = createRouter({
568570
history: createWebHistory(),

playground/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createApp } from 'vue'
22
import App from './App.vue'
3+
// FIXME:
34
import { DataLoaderPlugin } from 'vue-router/auto'
5+
// import { DataLoaderPlugin } from 'unplugin-vue-router/runtime'
46
import { MutationCache, QueryCache, VueQueryPlugin } from '@tanstack/vue-query'
57
import { createPinia } from 'pinia'
68
import { QueryPlugin } from '@pinia/colada'

playground/src/pages/users/query.[id].vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
// FIXME: should be able to import from vue-router or auto import
33
// import { defineQueryLoader } from 'unplugin-vue-router/data-loaders/vue-query'
44
5-
import {
6-
type TypesConfig,
7-
type RouteRecordName,
8-
} from 'unplugin-vue-router/types'
5+
import { type RouteRecordName } from 'vue-router'
96
import { computed } from 'vue'
107
const a: RouteRecordName = '/articles'
118

playground/typed-router.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@ declare module 'vue-router/auto-routes' {
6666
'/with-extension': RouteRecordInfo<'/with-extension', '/with-extension', Record<never, never>, Record<never, never>>,
6767
}
6868
}
69-

0 commit comments

Comments
 (0)