48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
/**
|
|
* router/index.ts
|
|
*
|
|
* Automatic routes for `./src/pages/*.vue`
|
|
*/
|
|
|
|
// Composables
|
|
import {createRouter, createWebHistory} from 'vue-router/auto'
|
|
import Search from "@/pages/Search.vue";
|
|
import BookDetails from "@/pages/BookDetails.vue";
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
routes: [{
|
|
path: "/",
|
|
name: "search",
|
|
component: Search
|
|
},
|
|
{
|
|
path: "/book/:id",
|
|
name: "book",
|
|
component: BookDetails
|
|
}
|
|
|
|
],
|
|
})
|
|
|
|
// 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
|