From b29f635646eb68e6a1035b1ac8106cc8f31514d9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 6 May 2022 12:02:35 +0100 Subject: [PATCH] fix(nuxt): normalise window location for universal router (#4841) --- packages/nuxt/src/app/plugins/router.ts | 8 +++++--- packages/nuxt/src/pages/runtime/router.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/app/plugins/router.ts b/packages/nuxt/src/app/plugins/router.ts index 68357a41d5..0dc9661344 100644 --- a/packages/nuxt/src/app/plugins/router.ts +++ b/packages/nuxt/src/app/plugins/router.ts @@ -1,9 +1,9 @@ import { reactive, h } from 'vue' -import { parseURL, parseQuery } from 'ufo' +import { parseURL, parseQuery, withoutBase } from 'ufo' import { createError } from 'h3' import { defineNuxtPlugin } from '..' import { callWithNuxt } from '../nuxt' -import { clearError, navigateTo, throwError } from '#app' +import { clearError, navigateTo, throwError, useRuntimeConfig } from '#app' interface Route { /** Percentage encoded pathname section of the URL. */ @@ -86,7 +86,9 @@ interface Router { } export default defineNuxtPlugin<{ route: Route, router: Router }>((nuxtApp) => { - const initialURL = process.client ? window.location.href : nuxtApp.ssrContext.url + const initialURL = process.client + ? withoutBase(window.location.pathname, useRuntimeConfig().app.baseURL) + window.location.search + window.location.hash + : nuxtApp.ssrContext.url const routes = [] const hooks: { [key in keyof RouterHooks]: RouterHooks[key][] } = { diff --git a/packages/nuxt/src/pages/runtime/router.ts b/packages/nuxt/src/pages/runtime/router.ts index f5977b5f47..e63ebb05ac 100644 --- a/packages/nuxt/src/pages/runtime/router.ts +++ b/packages/nuxt/src/pages/runtime/router.ts @@ -54,7 +54,7 @@ export default defineNuxtPlugin(async (nuxtApp) => { nuxtApp.vueApp.component('NuxtNestedPage', NuxtPage) nuxtApp.vueApp.component('NuxtChild', NuxtPage) - const { baseURL } = useRuntimeConfig().app + const baseURL = useRuntimeConfig().app.baseURL const routerHistory = process.client ? createWebHistory(baseURL) : createMemoryHistory(baseURL)