Skip to content

Commit fa4d655

Browse files
committed
fix(router): add workaround for dynamic import error
1 parent 1314f3c commit fa4d655

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

template/javascript/base/src/router/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,23 @@ import { createRouter, createWebHistory } from 'vue-router/auto'
1111
const router = createRouter({
1212
history: createWebHistory(import.meta.env.BASE_URL),
1313
})
14+
// Workaround for https://github.com/vitejs/vite/issues/11804
15+
router.onError((err, to) => {
16+
if (err?.message?.includes?.('Failed to fetch dynamically imported module')) {
17+
if (!localStorage.getItem('vuetify:dynamic-reload')) {
18+
console.log('Reloading page to fix dynamic import error')
19+
localStorage.setItem('vuetify:dynamic-reload', 'true')
20+
location.assign(to.fullPath)
21+
} else {
22+
console.error('Dynamic import error, reloading page did not fix it', err)
23+
}
24+
} else {
25+
console.error(err)
26+
}
27+
})
28+
29+
router.isReady().then(() => {
30+
localStorage.removeItem('vuetify:dynamic-reload')
31+
})
1432

1533
export default router

template/typescript/base/src/router/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,23 @@ const router = createRouter({
1111
history: createWebHistory(import.meta.env.BASE_URL),
1212
})
1313

14+
// Workaround for https://github.com/vitejs/vite/issues/11804
15+
router.onError((err, to) => {
16+
if (err?.message?.includes?.('Failed to fetch dynamically imported module')) {
17+
if (!localStorage.getItem('vuetify:dynamic-reload')) {
18+
console.log('Reloading page to fix dynamic import error')
19+
localStorage.setItem('vuetify:dynamic-reload', 'true')
20+
location.assign(to.fullPath)
21+
} else {
22+
console.error('Dynamic import error, reloading page did not fix it', err)
23+
}
24+
} else {
25+
console.error(err)
26+
}
27+
})
28+
29+
router.isReady().then(() => {
30+
localStorage.removeItem('vuetify:dynamic-reload')
31+
})
32+
1433
export default router

0 commit comments

Comments
 (0)