]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(types): allow components defined via defineComponent (#421)
authorEduardo San Martin Morote <posva@users.noreply.github.com>
Mon, 31 Aug 2020 09:11:16 +0000 (11:11 +0200)
committerGitHub <noreply@github.com>
Mon, 31 Aug 2020 09:11:16 +0000 (11:11 +0200)
Co-authored-by: cexbrayat <cedric@ninja-squad.com>
src/RouterView.ts
src/types/index.ts
test-dts/createRouter.test-d.ts

index f68cc658e14fbea1414220f0bd3c23e12c5c5c86..5f5dba406c1831d8cc268d6938c6092ef8256a46 100644 (file)
@@ -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
index fd9e14a2f94b406638a78b7c825ec05847558b92..e858f55498a654e14741b2c8e71ac28fc4e385e9 100644 (file)
@@ -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'
index ca647b3e39b8f89132149e1e4d3c5aff834dbf46..75ff3b872335db05435ddc376a2f0499dc7578d2 100644 (file)
@@ -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,