fix(nuxt): wrap universal router currentRoute in Ref (#25026)

This commit is contained in:
Daniel Roe 2024-01-03 12:23:22 +00:00 committed by GitHub
parent afbc4080b1
commit 75b81d70b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import { defineComponent, h, isReadonly, reactive } from 'vue'
import type { Ref } from 'vue'
import { computed, 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'
@ -71,7 +72,7 @@ interface RouterHooks {
}
interface Router {
currentRoute: Route
currentRoute: Ref<Route>
isReady: () => Promise<void>
options: {}
install: () => Promise<void>
@ -158,8 +159,21 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
}
}
const currentRoute = computed(() => route)
// TODO: remove this in v3.10
for (const key in route) {
Object.defineProperty(currentRoute, key, {
get () {
if (import.meta.dev) {
console.warn(`\`currentRoute.${key}\` is deprecated. Use \`currentRoute.value.${key}\` instead.`)
}
return route[key as keyof Route]
}
})
}
const router: Router = {
currentRoute: route,
currentRoute,
isReady: () => Promise.resolve(),
// These options provide a similar API to vue-router but have no effect
options: {},