Skip to content

Commit e462bb2

Browse files
committed
feat(types): RouterConfig for multiple components (vuejs#3217)
1 parent ba0bffa commit e462bb2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Diff for: types/router.d.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,30 @@ export interface PathToRegexpOptions {
8989
end?: boolean
9090
}
9191

92-
export interface RouteConfig {
92+
interface _RouteConfigBase {
9393
path: string
9494
name?: string
95-
component?: Component
96-
components?: Dictionary<Component>
9795
redirect?: RedirectOption
9896
alias?: string | string[]
9997
children?: RouteConfig[]
10098
meta?: any
10199
beforeEnter?: NavigationGuard
102-
props?: boolean | Object | RoutePropsFunction
103100
caseSensitive?: boolean
104101
pathToRegexpOptions?: PathToRegexpOptions
105102
}
106103

104+
type RouteConfigSingleView = _RouteConfigBase & {
105+
component?: Component
106+
props?: boolean | Object | RoutePropsFunction
107+
}
108+
109+
type RouteConfigMultipleViews = _RouteConfigBase & {
110+
components?: Dictionary<Component>
111+
props?: Dictionary<boolean | Object | RoutePropsFunction>
112+
}
113+
114+
export type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews
115+
107116
export interface RouteRecord {
108117
path: string
109118
regex: RegExp

Diff for: types/test/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Vue.use(VueRouter)
88
const Home = { template: '<div>home</div>' }
99
const Foo = { template: '<div>foo</div>' }
1010
const Bar = { template: '<div>bar</div>' }
11+
const Abc = { template: '<div>abc</div>' }
1112
const Async = () => Promise.resolve({ template: '<div>async</div>' })
1213

1314
const Hook: ComponentOptions<Vue> = {
@@ -76,6 +77,7 @@ const router = new VueRouter({
7677
components: {
7778
default: Foo,
7879
bar: Bar,
80+
abc: Abc,
7981
asyncComponent: Async
8082
},
8183
meta: { auth: true },
@@ -88,6 +90,7 @@ const router = new VueRouter({
8890
props: {
8991
default: true,
9092
bar: { id: 123 },
93+
abc: route => route.params,
9194
asyncComponent: (route: Route) => route.params
9295
}
9396
},

0 commit comments

Comments
 (0)