mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-30 11:47:55 +01:00
fix(vue): stub vue-router
This commit is contained in:
@@ -6,7 +6,52 @@ import type { NuxtApp } from '#app'
|
|||||||
import { useColorMode as useColorModeVueUse } from '@vueuse/core'
|
import { useColorMode as useColorModeVueUse } from '@vueuse/core'
|
||||||
|
|
||||||
export { useHead } from '@unhead/vue'
|
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({})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Use a runtime check to determine which implementation to use
|
||||||
|
let _useRoute = useRouteStub
|
||||||
|
let _useRouter = useRouterStub
|
||||||
|
|
||||||
|
// Try to import from vue-router
|
||||||
|
try {
|
||||||
|
// This will throw if vue-router is not available
|
||||||
|
const vueRouter = await import('vue-router')
|
||||||
|
if (vueRouter.useRoute && vueRouter.useRouter) {
|
||||||
|
// Type assertion with unknown to fix type compatibility issues
|
||||||
|
_useRoute = vueRouter.useRoute as unknown as typeof _useRoute
|
||||||
|
_useRouter = vueRouter.useRouter as unknown as typeof _useRouter
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Use the stubs if vue-router is not available
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useRoute = _useRoute
|
||||||
|
export const useRouter = _useRouter
|
||||||
|
|
||||||
export { defineShortcuts } from '../composables/defineShortcuts'
|
export { defineShortcuts } from '../composables/defineShortcuts'
|
||||||
export { useLocale } from '../composables/useLocale'
|
export { useLocale } from '../composables/useLocale'
|
||||||
|
|||||||
Reference in New Issue
Block a user