Skip to content

Instantly share code, notes, and snippets.

@Haythamasalama
Last active October 8, 2023 15:40
Show Gist options
  • Save Haythamasalama/ef8035dc3b5a33dedf051e2caf3a00d1 to your computer and use it in GitHub Desktop.
Save Haythamasalama/ef8035dc3b5a33dedf051e2caf3a00d1 to your computer and use it in GitHub Desktop.
Auto-reload page when chunk assets are not found or failed to import in Vue.js
import { createRouter, createWebHistory } from 'vue-router';
import routes from '~pages';
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: routes,
});
router.onError((err) => {
const messages = [
'Importing a module script failed', // safari
'Failed to fetch dynamically imported module' // edge & chrome
];
if (messages.some((message) => err?.message.includes(message))) {
router.go(0);
return;
}
});
export default router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment