From: Eduardo San Martin Morote Date: Mon, 31 Aug 2020 09:11:16 +0000 (+0200) Subject: fix(types): allow components defined via defineComponent (#421) X-Git-Tag: v4.0.0-beta.8~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e47c84c74a97ae7bb9095ea75f98a6fa8a216532;p=thirdparty%2Fvuejs%2Frouter.git fix(types): allow components defined via defineComponent (#421) Co-authored-by: cexbrayat --- diff --git a/src/RouterView.ts b/src/RouterView.ts index f68cc658..5f5dba40 100644 --- a/src/RouterView.ts +++ b/src/RouterView.ts @@ -62,7 +62,7 @@ export const RouterViewImpl = defineComponent({ : null } - // props from route configration + // props from route configuration const routePropsOption = matchedRoute.props[props.name] const routeProps = routePropsOption ? routePropsOption === true diff --git a/src/types/index.ts b/src/types/index.ts index fd9e14a2..e858f554 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,6 @@ import { LocationQuery, LocationQueryRaw } from '../query' import { PathParserOptions } from '../matcher' -import { Ref, ComputedRef, Component, ComponentPublicInstance } from 'vue' +import { Ref, ComputedRef, ComponentPublicInstance, Component } from 'vue' import { RouteRecord, RouteRecordNormalized } from '../matcher/types' import { HistoryState } from '../history/common' import { NavigationFailure } from '../errors' diff --git a/test-dts/createRouter.test-d.ts b/test-dts/createRouter.test-d.ts index ca647b3e..75ff3b87 100644 --- a/test-dts/createRouter.test-d.ts +++ b/test-dts/createRouter.test-d.ts @@ -5,13 +5,40 @@ import { NavigationGuardNext, RouteLocationNormalized, } from './index' -import { createApp, defineComponent } from 'vue' +import { createApp, defineComponent, h } from 'vue' const component = defineComponent({}) +const WithProps = defineComponent({ + props: { + id: { + type: String, + required: true, + }, + }, +}) + +const Foo = defineComponent({ + props: { + test: String, + }, + setup() { + return { + title: 'homepage', + } + }, + render() { + return h('div', `${this.title}: ${this.test}`) + }, +}) + const router = createRouter({ history: createWebHistory(), - routes: [{ path: '/', component }], + routes: [ + { path: '/', component }, + { path: '/foo', component: Foo }, + { path: '/', component: WithProps }, + ], parseQuery: search => ({}), stringifyQuery: query => '', strict: true,