diff --git a/flow/declarations.js b/flow/declarations.js index 942aa73bf..b0b3c61c5 100644 --- a/flow/declarations.js +++ b/flow/declarations.js @@ -48,6 +48,8 @@ declare type RouterOptions = { declare type RedirectOption = RawLocation | ((to: Route) => RawLocation) +type RoutePropsFunction = (route: Route) => Object + declare type RouteConfig = { path: string; name?: string; @@ -58,7 +60,7 @@ declare type RouteConfig = { children?: Array; beforeEnter?: NavigationGuard; meta?: any; - props?: boolean | Object | Function; + props?: boolean | Object | RoutePropsFunction | Dictionary; caseSensitive?: boolean; pathToRegexpOptions?: PathToRegexpOptions; } @@ -74,7 +76,7 @@ declare type RouteRecord = { matchAs: ?string; beforeEnter: ?NavigationGuard; meta: any; - props: boolean | Object | Function | Dictionary; + props: Dictionary; } declare type Location = { diff --git a/src/create-route-map.js b/src/create-route-map.js index 0f790108c..0da7dd775 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -83,6 +83,7 @@ function addRouteRecord ( route.props == null ? {} : route.components + // $flow-disable-line ? route.props : { default: route.props } } diff --git a/types/router.d.ts b/types/router.d.ts index dc4516bbd..902688b88 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -81,7 +81,7 @@ export interface RouteConfig { children?: RouteConfig[]; meta?: any; beforeEnter?: NavigationGuard; - props?: boolean | Object | RoutePropsFunction; + props?: boolean | Object | RoutePropsFunction | Dictionary; caseSensitive?: boolean; pathToRegexpOptions?: PathToRegexpOptions; } @@ -101,7 +101,7 @@ export interface RouteRecord { redirect: (location: RawLocation) => void, next: () => void ) => any; - props: boolean | Object | RoutePropsFunction | Dictionary; + props: Dictionary; } export interface Location { diff --git a/types/test/index.ts b/types/test/index.ts index abb5395b3..97aed35bb 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -80,6 +80,11 @@ const router = new VueRouter({ from.params; next({ name: "home" }); next(); + }, + props: { + default: true, + bar: { id: 123 }, + asyncComponent: (route: Route) => route.params } }, { @@ -121,6 +126,9 @@ matched.forEach(m => { const name: string | undefined = m.name; const parant: RouteRecord | undefined = m.parent; const redirect: RedirectOption | undefined = m.redirect; + const props: { + [key: string]: boolean | Object | ((route: Route) => Object) + } = m.props; }); const unregister = router.beforeEach((to, from, next) => {