Skip to content

Commit dab86c5

Browse files
javierturyposva
andauthored
feat(types): RouterConfig for multiple components (#3217) (#3218)
* feat(types): RouterConfig for multiple components (#3217) * Apply suggestions from code review Co-authored-by: Eduardo San Martin Morote <[email protected]>
1 parent ba0bffa commit dab86c5

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

types/router.d.ts

+14-5
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[]
99-
children?: RouteConfig[]
10097
meta?: any
10198
beforeEnter?: NavigationGuard
102-
props?: boolean | Object | RoutePropsFunction
10399
caseSensitive?: boolean
104100
pathToRegexpOptions?: PathToRegexpOptions
105101
}
106102

103+
interface RouteConfigSingleView extends _RouteConfigBase {
104+
component?: Component
105+
props?: boolean | Object | RoutePropsFunction
106+
}
107+
108+
interface RouteConfigMultipleViews extends _RouteConfigBase {
109+
components?: Dictionary<Component>
110+
children?: RouteConfig[]
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

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)