Skip to content

Commit

Permalink
fix: handle hash urls and app.baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 7, 2023
1 parent 99ec231 commit 98b2869
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/nuxt/src/app/plugins/chunk-reload.client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { defineNuxtPlugin } from '#app/nuxt'
import { joinURL } from 'ufo'
import { defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
import { useRouter } from '#app/composables/router'
import { reloadNuxtApp } from '#app/composables/chunk'

export default defineNuxtPlugin((nuxtApp) => {
const router = useRouter()
const config = useRuntimeConfig()

const chunkErrors = new Set()

Expand All @@ -12,7 +14,9 @@ export default defineNuxtPlugin((nuxtApp) => {

router.onError((error, to) => {
if (chunkErrors.has(error)) {
reloadNuxtApp({ path: to.fullPath })
const isHash = 'href' in to && (to.href as string).startsWith('#')
const path = isHash ? config.app.baseURL + (to as any).href : joinURL(config.app.baseURL, to.fullPath)
reloadNuxtApp({ path })
}
})
})

0 comments on commit 98b2869

Please sign in to comment.