2022-01-26 11:56:24 +00:00
|
|
|
import { KeepAliveProps, TransitionProps, UnwrapRef } from 'vue'
|
2022-10-10 10:18:20 +00:00
|
|
|
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRedirectOption } from 'vue-router'
|
|
|
|
import type { NuxtError } from '#app'
|
2022-01-17 18:27:23 +00:00
|
|
|
|
|
|
|
export interface PageMeta {
|
|
|
|
[key: string]: any
|
2022-10-10 10:18:20 +00:00
|
|
|
/**
|
|
|
|
* Validate whether a given route can validly be rendered with this page.
|
|
|
|
*
|
|
|
|
* Return true if it is valid, or false if not. If another match can't be found,
|
|
|
|
* this will mean a 404. You can also directly return an object with
|
|
|
|
* statusCode/statusMessage to respond immediately with an error (other matches
|
|
|
|
* will not be checked).
|
|
|
|
*/
|
|
|
|
validate?: (route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>
|
2022-09-22 13:54:34 +00:00
|
|
|
/**
|
|
|
|
* Where to redirect if the route is directly matched. The redirection happens
|
|
|
|
* before any navigation guard and triggers a new navigation with the new
|
|
|
|
* target location.
|
|
|
|
*/
|
|
|
|
redirect?: RouteRecordRedirectOption
|
|
|
|
/**
|
|
|
|
* Aliases for the record. Allows defining extra paths that will behave like a
|
|
|
|
* copy of the record. Allows having paths shorthands like `/users/:id` and
|
|
|
|
* `/u/:id`. All `alias` and `path` values must share the same params.
|
|
|
|
*/
|
|
|
|
alias?: string | string[]
|
2022-02-07 10:17:28 +00:00
|
|
|
pageTransition?: boolean | TransitionProps
|
|
|
|
layoutTransition?: boolean | TransitionProps
|
2022-02-07 11:32:04 +00:00
|
|
|
key?: false | string | ((route: RouteLocationNormalizedLoaded) => string)
|
2022-02-07 10:17:28 +00:00
|
|
|
keepalive?: boolean | KeepAliveProps
|
2022-11-03 14:05:38 +00:00
|
|
|
/** You may define a name for this page's route. */
|
|
|
|
name?: string
|
|
|
|
/** You may define a path matcher, if you have a more complex pattern than can be expressed with the file name. */
|
|
|
|
path?: string
|
2022-10-19 12:43:03 +00:00
|
|
|
/** Set to `false` to avoid scrolling to top on page navigations */
|
|
|
|
scrollToTop?: boolean
|
2022-01-17 18:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
declare module 'vue-router' {
|
2022-01-26 11:56:24 +00:00
|
|
|
interface RouteMeta extends UnwrapRef<PageMeta> {}
|
2022-01-17 18:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const warnRuntimeUsage = (method: string) =>
|
|
|
|
console.warn(
|
|
|
|
`${method}() is a compiler-hint helper that is only usable inside ` +
|
2022-11-14 10:28:31 +00:00
|
|
|
'the script block of a single file component which is also a page. Its arguments should be ' +
|
|
|
|
'compiled away and passing it at runtime has no effect.'
|
2022-01-17 18:27:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
export const definePageMeta = (meta: PageMeta): void => {
|
|
|
|
if (process.dev) {
|
|
|
|
warnRuntimeUsage('definePageMeta')
|
|
|
|
}
|
|
|
|
}
|