Skip to content

Commit

Permalink
refactor(nuxt): use defineComponent to infer prop types for router-…
Browse files Browse the repository at this point in the history
…link stub
  • Loading branch information
danielroe committed Nov 28, 2023
1 parent 0eb9caf commit dc0e834
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/nuxt/src/app/plugins/router.ts
@@ -1,4 +1,4 @@
import { h, isReadonly, reactive } from 'vue'
import { defineComponent, h, isReadonly, reactive } from 'vue'
import { isEqual, joinURL, parseQuery, parseURL, stringifyParsedURL, stringifyQuery, withoutBase } from 'ufo'
import { createError } from 'h3'
import { defineNuxtPlugin, useRuntimeConfig } from '../nuxt'
Expand Down Expand Up @@ -188,10 +188,13 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
}
}

nuxtApp.vueApp.component('RouterLink', {
nuxtApp.vueApp.component('RouterLink', defineComponent({
functional: true,
props: {
to: String,
to: {
type: String,
required: true
},
custom: Boolean,
replace: Boolean,
// Not implemented
Expand All @@ -200,15 +203,15 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
ariaCurrentValue: String
},
setup: (props, { slots }) => {
const navigate = () => handleNavigation(props.to, props.replace)
const navigate = () => handleNavigation(props.to!, props.replace)
return () => {
const route = router.resolve(props.to)
const route = router.resolve(props.to!)
return props.custom
? slots.default?.({ href: props.to, navigate, route })
: h('a', { href: props.to, onClick: (e: MouseEvent) => { e.preventDefault(); return navigate() } }, slots)
}
}
})
}))

if (import.meta.client) {
window.addEventListener('popstate', (event) => {
Expand Down

0 comments on commit dc0e834

Please sign in to comment.