From 9a3349f7902f7b8720f815326a66b11ce40e5165 Mon Sep 17 00:00:00 2001 From: javiertury Date: Tue, 2 Jun 2020 19:23:45 +0200 Subject: [PATCH] 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 } },