Compare commits

...

3 Commits

Author SHA1 Message Date
Benjamin Canac
723065afa7 up 2025-03-07 15:19:38 +01:00
Benjamin Canac
e67305e412 up 2025-03-07 15:11:17 +01:00
Benjamin Canac
33ed3935a3 fix(vue): stub vue-router 2025-03-07 15:00:10 +01:00

View File

@@ -6,7 +6,87 @@ import type { NuxtApp } from '#app'
import { useColorMode as useColorModeVueUse } from '@vueuse/core'
export { useHead } from '@unhead/vue'
export { useRoute, useRouter } from 'vue-router'
// Create stub implementations for vue-router
export const useRouteStub = () => ({
path: '',
name: null,
params: {},
query: {},
hash: '',
fullPath: '',
matched: [],
meta: {},
redirectedFrom: undefined
})
export const useRouterStub = () => ({
push: () => Promise.resolve(),
replace: () => Promise.resolve(),
go: () => Promise.resolve(),
back: () => Promise.resolve(),
forward: () => Promise.resolve(),
beforeEach: () => () => {},
afterEach: () => () => {},
getRoutes: () => [],
hasRoute: () => false,
currentRoute: ref({})
})
// Create a module-level cache for the imported modules
const moduleCache: Record<string, any> = {}
// Function to dynamically import a module and cache the result
function lazyImport(moduleName: string) {
return () => {
if (!moduleCache[moduleName]) {
moduleCache[moduleName] = import(/* @vite-ignore */ moduleName).catch(() => ({}))
}
return moduleCache[moduleName]
}
}
// Lazy import vue-router
const importVueRouter = lazyImport('vue-router')
// Create wrapper functions that will dynamically import or use stubs
export function useRoute() {
// Try to get the real implementation
const vueRouterModule = moduleCache['vue-router']
if (vueRouterModule && vueRouterModule.useRoute) {
return vueRouterModule.useRoute()
}
// If not available yet, try to import it
importVueRouter().then((module: any) => {
if (module && module.useRoute) {
// Module loaded successfully, but it's too late for this call
// Future calls will use the cached module
}
})
// Fall back to stub for this call
return useRouteStub()
}
export function useRouter() {
// Try to get the real implementation
const vueRouterModule = moduleCache['vue-router']
if (vueRouterModule && vueRouterModule.useRouter) {
return vueRouterModule.useRouter()
}
// If not available yet, try to import it
importVueRouter().then((module: any) => {
if (module && module.useRouter) {
// Module loaded successfully, but it's too late for this call
// Future calls will use the cached module
}
})
// Fall back to stub for this call
return useRouterStub()
}
export { defineShortcuts } from '../composables/defineShortcuts'
export { useLocale } from '../composables/useLocale'