From 9a3349f7902f7b8720f815326a66b11ce40e5165 Mon Sep 17 00:00:00 2001 From: javiertury Date: Tue, 2 Jun 2020 19:23:45 +0200 Subject: [PATCH 1/2] feat(types): RouterConfig for multiple components (#3217) --- types/router.d.ts | 17 +++++++++++++---- types/test/index.ts | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/types/router.d.ts b/types/router.d.ts index 424a48430..31fa73225 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -89,21 +89,30 @@ export interface PathToRegexpOptions { end?: boolean } -export interface RouteConfig { +interface _RouteConfigBase { path: string name?: string - component?: Component - components?: Dictionary redirect?: RedirectOption alias?: string | string[] children?: RouteConfig[] meta?: any beforeEnter?: NavigationGuard - props?: boolean | Object | RoutePropsFunction caseSensitive?: boolean pathToRegexpOptions?: PathToRegexpOptions } +interface RouteConfigSingleView extends _RouteConfigBase { + component?: Component + props?: boolean | Object | RoutePropsFunction +} + +interface RouteConfigMultipleViews extends _RouteConfigBase { + components?: Dictionary + props?: Dictionary +} + +export type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews + export interface RouteRecord { path: string regex: RegExp diff --git a/types/test/index.ts b/types/test/index.ts index 4afa858b0..328e8c980 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -8,6 +8,7 @@ Vue.use(VueRouter) const Home = { template: '
home
' } const Foo = { template: '
foo
' } const Bar = { template: '
bar
' } +const Abc = { template: '
abc
' } const Async = () => Promise.resolve({ template: '
async
' }) const Hook: ComponentOptions = { @@ -76,6 +77,7 @@ const router = new VueRouter({ components: { default: Foo, bar: Bar, + abc: Abc, asyncComponent: Async }, meta: { auth: true }, @@ -88,6 +90,7 @@ const router = new VueRouter({ props: { default: true, bar: { id: 123 }, + abc: route => route.params, asyncComponent: (route: Route) => route.params } }, From 4620ef2c6e93c3bbeca28c6012630131bedc1f52 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 4 Jun 2020 12:00:44 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- types/router.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/router.d.ts b/types/router.d.ts index 31fa73225..09bca5032 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -94,7 +94,6 @@ interface _RouteConfigBase { name?: string redirect?: RedirectOption alias?: string | string[] - children?: RouteConfig[] meta?: any beforeEnter?: NavigationGuard caseSensitive?: boolean @@ -108,6 +107,7 @@ interface RouteConfigSingleView extends _RouteConfigBase { interface RouteConfigMultipleViews extends _RouteConfigBase { components?: Dictionary + children?: RouteConfig[] props?: Dictionary }