2022-01-17 18:27:23 +00:00
|
|
|
import { ComputedRef, /* KeepAliveProps, */ Ref, TransitionProps } from 'vue'
|
2021-12-17 09:15:03 +00:00
|
|
|
import type { Router, RouteLocationNormalizedLoaded } from 'vue-router'
|
|
|
|
import { useNuxtApp } from '#app'
|
|
|
|
|
|
|
|
export const useRouter = () => {
|
|
|
|
return useNuxtApp().$router as Router
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:37:00 +00:00
|
|
|
export const useRoute = () => {
|
|
|
|
return useNuxtApp()._route as RouteLocationNormalizedLoaded
|
2021-12-17 09:15:03 +00:00
|
|
|
}
|
2022-01-17 18:27:23 +00:00
|
|
|
|
|
|
|
export interface PageMeta {
|
|
|
|
[key: string]: any
|
|
|
|
transition?: false | TransitionProps
|
|
|
|
layout?: false | string | Ref<false | string> | ComputedRef<false | string>
|
|
|
|
// TODO: https://github.com/vuejs/vue-next/issues/3652
|
|
|
|
// keepalive?: false | KeepAliveProps
|
|
|
|
}
|
|
|
|
|
|
|
|
declare module 'vue-router' {
|
|
|
|
interface RouteMeta extends PageMeta {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const warnRuntimeUsage = (method: string) =>
|
|
|
|
console.warn(
|
|
|
|
`${method}() is a compiler-hint helper that is only usable inside ` +
|
|
|
|
'<script setup> of a single file component. Its arguments should be ' +
|
|
|
|
'compiled away and passing it at runtime has no effect.'
|
|
|
|
)
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
export const definePageMeta = (meta: PageMeta): void => {
|
|
|
|
if (process.dev) {
|
|
|
|
warnRuntimeUsage('definePageMeta')
|
|
|
|
}
|
|
|
|
}
|