Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/.vitepress/twoslash-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare module 'vue-router/auto-routes' {
'/users/:id',
{ id: ParamValue<true> },
{ id: ParamValue<false> },
'/users/[id]/edit'
| '/users/[id]/edit'
>
'/users/[id]/edit': RouteRecordInfo<
'/users/[id]/edit',
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ declare module 'vue-router/auto-routes' {
{ path: ParamValue<false> },
// this is a union of all children route names
// if the route does not have nested routes, pass `never` or omit this generic entirely
'custom-dynamic-child-name'
| 'custom-dynamic-child-name'
>
'custom-dynamic-child-name': RouteRecordInfo<
'custom-dynamic-child-name',
Expand Down
690 changes: 563 additions & 127 deletions playground/typed-router.d.ts

Large diffs are not rendered by default.

44 changes: 31 additions & 13 deletions src/codegen/generateRouteFileInfoMap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ describe('generateRouteFileInfoMap', () => {
.toMatchInlineSnapshot(`
"export interface _RouteFileInfoMap {
'src/pages/index.vue': {
routes: '/'
routes:
| '/'
views: never
}
'src/pages/a.vue': {
routes: '/a'
routes:
| '/a'
views: never
}
'src/pages/b.vue': {
routes: '/b'
routes:
| '/b'
views: never
}
'src/pages/c.vue': {
routes: '/c'
routes:
| '/c'
views: never
}
}"
Expand All @@ -50,11 +54,15 @@ describe('generateRouteFileInfoMap', () => {
.toMatchInlineSnapshot(`
"export interface _RouteFileInfoMap {
'src/pages/parent.vue': {
routes: '/parent' | '/parent/child'
views: 'default'
routes:
| '/parent'
| '/parent/child'
views:
| 'default'
}
'src/pages/parent/child.vue': {
routes: '/parent/child'
routes:
| '/parent/child'
views: never
}
}"
Expand All @@ -70,15 +78,21 @@ describe('generateRouteFileInfoMap', () => {
.toMatchInlineSnapshot(`
"export interface _RouteFileInfoMap {
'src/pages/parent.vue': {
routes: '/parent' | '/parent/child'
views: 'default' | 'test'
routes:
| '/parent'
| '/parent/child'
views:
| 'default'
| 'test'
}
'src/pages/parent/child.vue': {
routes: '/parent/child'
routes:
| '/parent/child'
views: never
}
'src/pages/parent/[email protected]': {
routes: '/parent/child'
routes:
| '/parent/child'
views: never
}
}"
Expand All @@ -98,11 +112,15 @@ describe('generateRouteFileInfoMap', () => {
.toMatchInlineSnapshot(`
"export interface _RouteFileInfoMap {
'index.vue': {
routes: '/' | '/home'
routes:
| '/'
| '/home'
views: never
}
'nested/index.vue': {
routes: '/nested/path' | '/unnested'
routes:
| '/nested/path'
| '/unnested'
views: never
}
}"
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/generateRouteFileInfoMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export function generateRouteFileInfoMap(
([file, { routes, views }]) =>
`
'${file}': {
routes: ${routes.map((name) => `'${name}'`).join(' | ')}
views: ${views.length > 0 ? views.map((view) => `'${view}'`).join(' | ') : 'never'}
routes:${routes.map((name) => `\n | '${name}'`).join('\n')}
views:${views.length > 0 ? views.map((view) => `\n | '${view}'`).join('\n') : ' never'}
}`
)
.join('\n')
Expand Down
Loading
Loading