diff --git a/src/vue-router.ts b/src/vue-router.ts index a882b0f..4a88330 100644 --- a/src/vue-router.ts +++ b/src/vue-router.ts @@ -44,40 +44,13 @@ export function useRouter(): Router { } -export interface RouteLocationNormalized extends Route {} -export interface RouteLocationNormalizedLoaded extends Route {} - - -function createReactiveRoute(initialRoute: Route) { - const routeRef = shallowRef(initialRoute); - const computedRoute = {} as { - [key in keyof Route]: ComputedRef - } - for (const key of [ - 'name', 'meta', 'path', 'hash', 'query', - 'params', 'fullPath', 'matched', 'redirectedFrom' - ] as const) { - computedRoute[key] = computed(() => routeRef.value[key]); - } - return [ - reactive(computedRoute), - (route: Route) => { - routeRef.value = route - }, - ] as const -} - -let reactiveCurrentRoute: Route - -export function useRoute(): RouteLocationNormalizedLoaded { - const router = useRouter() - if (!router) return undefined as any - if (!reactiveCurrentRoute) { - let setCurrentRoute: (route: Route) => void - [reactiveCurrentRoute, setCurrentRoute] = createReactiveRoute(router.currentRoute) - router.afterEach(to => setCurrentRoute(to)) +export function useRoute(): Route { + const inst = getCurrentInstance() + if (inst) { + return inst.proxy.$route as Route } - return reactiveCurrentRoute + warn(OUT_OF_SCOPE) + return undefined as any }