Skip to content

Commit a9052ec

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

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: types/router.d.ts

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

92-
export interface RouteConfig {
92+
interface _RouteConfigBase {
9393
path: string
9494
name?: string
9595
component?: Component
@@ -104,6 +104,18 @@ export interface RouteConfig {
104104
pathToRegexpOptions?: PathToRegexpOptions
105105
}
106106

107+
type RouteConfigSingleView = _RouteConfigBase | {
108+
component?: Component
109+
props?: boolean | Object | RoutePropsFunction
110+
}
111+
112+
type RouteConfigMultipleViews = _RouteConfigBase | {
113+
components?: Dictionary<Component>
114+
props?: Dictionary<boolean | Object | RoutePropsFunction>
115+
}
116+
117+
export type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews
118+
107119
export interface RouteRecord {
108120
path: string
109121
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)