fix(nuxt): normalise window location for universal router (#4841)

This commit is contained in:
Daniel Roe 2022-05-06 12:02:35 +01:00 committed by GitHub
parent 750460693e
commit b29f635646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -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][] } = {

View File

@ -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)