Skip to content

Commit

Permalink
fix(router): add workaround for dynamic import error
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Jul 6, 2024
1 parent 1314f3c commit fa4d655
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions template/javascript/base/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,23 @@ import { createRouter, createWebHistory } from 'vue-router/auto'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
})
// Workaround for https://github.com/vitejs/vite/issues/11804
router.onError((err, to) => {
if (err?.message?.includes?.('Failed to fetch dynamically imported module')) {
if (!localStorage.getItem('vuetify:dynamic-reload')) {
console.log('Reloading page to fix dynamic import error')
localStorage.setItem('vuetify:dynamic-reload', 'true')
location.assign(to.fullPath)
} else {
console.error('Dynamic import error, reloading page did not fix it', err)
}
} else {
console.error(err)
}
})

router.isReady().then(() => {
localStorage.removeItem('vuetify:dynamic-reload')
})

export default router
19 changes: 19 additions & 0 deletions template/typescript/base/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,23 @@ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
})

// Workaround for https://github.com/vitejs/vite/issues/11804
router.onError((err, to) => {
if (err?.message?.includes?.('Failed to fetch dynamically imported module')) {
if (!localStorage.getItem('vuetify:dynamic-reload')) {
console.log('Reloading page to fix dynamic import error')
localStorage.setItem('vuetify:dynamic-reload', 'true')
location.assign(to.fullPath)
} else {
console.error('Dynamic import error, reloading page did not fix it', err)
}
} else {
console.error(err)
}
})

router.isReady().then(() => {
localStorage.removeItem('vuetify:dynamic-reload')
})

export default router

0 comments on commit fa4d655

Please sign in to comment.