From 75b81d70b8728b07fe80e4f01f822490e14ebe13 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 3 Jan 2024 12:23:22 +0000 Subject: [PATCH] fix(nuxt): wrap universal router `currentRoute` in `Ref` (#25026) --- packages/nuxt/src/app/plugins/router.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/app/plugins/router.ts b/packages/nuxt/src/app/plugins/router.ts index b12c829c15..15ab8d866c 100644 --- a/packages/nuxt/src/app/plugins/router.ts +++ b/packages/nuxt/src/app/plugins/router.ts @@ -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 isReady: () => Promise options: {} install: () => Promise @@ -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: {},