Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix: normalize router base with hash
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 4, 2022
1 parent bf0e2e4 commit dc7a3ca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/nuxt/src/pages/runtime/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare module 'vue' {
}
}

// https://github.dev/vuejs/router/blob/main/src/history/html5.ts#L33-L56
// https://github.com/vuejs/router/blob/4a0cc8b9c1e642cdf47cc007fa5bbebde70afc66/packages/router/src/history/html5.ts#L37
function createCurrentLocation (
base: string,
location: Location
Expand All @@ -55,16 +55,20 @@ export default defineNuxtPlugin(async (nuxtApp) => {
nuxtApp.vueApp.component('NuxtNestedPage', NuxtPage)
nuxtApp.vueApp.component('NuxtChild', NuxtPage)

const baseURL = useRuntimeConfig().app.baseURL
let routerBase = useRuntimeConfig().app.baseURL
if (routerOptions.hashMode && !routerBase.includes('#')) {
// allow the user to provide a `#` in the middle: `/base/#/app`
routerBase += '#'
}

const history = routerOptions.history?.(baseURL) ?? (process.client
? (routerOptions.hashMode ? createWebHashHistory(baseURL) : createWebHistory(baseURL))
: createMemoryHistory(baseURL)
const history = routerOptions.history?.(routerBase) ?? (process.client
? (routerOptions.hashMode ? createWebHashHistory(routerBase) : createWebHistory(routerBase))
: createMemoryHistory(routerBase)
)

const routes = routerOptions.routes?.(_routes) ?? _routes

const initialURL = process.server ? nuxtApp.ssrContext!.url : createCurrentLocation(baseURL, window.location)
const initialURL = process.server ? nuxtApp.ssrContext!.url : createCurrentLocation(routerBase, window.location)
const router = createRouter({
...routerOptions,
history,
Expand Down

0 comments on commit dc7a3ca

Please sign in to comment.