mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-15 20:48:12 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
723065afa7 | ||
|
|
e67305e412 | ||
|
|
33ed3935a3 |
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user