Skip to content

Commit

Permalink
fix(nuxt): normalise window location for universal router (nuxt#4841)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 6, 2022
1 parent 7504606 commit b29f635
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/nuxt/src/app/plugins/router.ts
Original file line number Diff line number Diff line change
@@ -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. */
Expand Down Expand Up @@ -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][] } = {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/pages/runtime/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b29f635

Please sign in to comment.