mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-11 11:18:06 +00:00
feat(nuxt): add type hints for NuxtPage
(#30704)
This commit is contained in:
parent
3db7e2e13d
commit
4be52d341f
@ -8,7 +8,7 @@ export { defineNuxtLink } from './components/index'
|
|||||||
export type { NuxtLinkOptions, NuxtLinkProps } from './components/index'
|
export type { NuxtLinkOptions, NuxtLinkProps } from './components/index'
|
||||||
export { _getAppConfig, updateAppConfig, useAppConfig } from './config'
|
export { _getAppConfig, updateAppConfig, useAppConfig } from './config'
|
||||||
export { cancelIdleCallback, requestIdleCallback } from './compat/idle-callback'
|
export { cancelIdleCallback, requestIdleCallback } from './compat/idle-callback'
|
||||||
export type { NuxtAppLiterals, NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext, PageMeta } from './types'
|
export type { NuxtAppLiterals, NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext, PageMeta, NuxtPageProps } from './types'
|
||||||
|
|
||||||
export const isVue2 = false
|
export const isVue2 = false
|
||||||
export const isVue3 = true
|
export const isVue3 = true
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export type { PageMeta } from '../pages/runtime/index'
|
export type { PageMeta, NuxtPageProps } from '../pages/runtime/index'
|
||||||
|
|
||||||
export interface NuxtAppLiterals {
|
export interface NuxtAppLiterals {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export { definePageMeta, defineRouteRules } from './composables'
|
export { definePageMeta, defineRouteRules } from './composables'
|
||||||
export type { PageMeta } from './composables'
|
export type { PageMeta } from './composables'
|
||||||
|
export type { NuxtPageProps } from './page'
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Fragment, Suspense, defineComponent, h, inject, nextTick, ref, watch } from 'vue'
|
import { Fragment, Suspense, defineComponent, h, inject, nextTick, ref, watch } from 'vue'
|
||||||
import type { KeepAliveProps, TransitionProps, VNode } from 'vue'
|
import type { AllowedComponentProps, ComponentCustomProps, ComponentPublicInstance, KeepAliveProps, TransitionProps, VNode, VNodeProps } from 'vue'
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded } from 'vue-router'
|
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouterViewProps } from 'vue-router'
|
||||||
|
|
||||||
import { generateRouteKey, toArray, wrapInKeepAlive } from './utils'
|
import { generateRouteKey, toArray, wrapInKeepAlive } from './utils'
|
||||||
import type { RouterViewSlotProps } from './utils'
|
import type { RouterViewSlotProps } from './utils'
|
||||||
@ -14,6 +14,23 @@ import { LayoutMetaSymbol, PageRouteSymbol } from '#app/components/injections'
|
|||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { appKeepalive as defaultKeepaliveConfig, appPageTransition as defaultPageTransition } from '#build/nuxt.config.mjs'
|
import { appKeepalive as defaultKeepaliveConfig, appPageTransition as defaultPageTransition } from '#build/nuxt.config.mjs'
|
||||||
|
|
||||||
|
export interface NuxtPageProps extends RouterViewProps {
|
||||||
|
/**
|
||||||
|
* Define global transitions for all pages rendered with the `NuxtPage` component.
|
||||||
|
*/
|
||||||
|
transition?: boolean | TransitionProps
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control state preservation of pages rendered with the `NuxtPage` component.
|
||||||
|
*/
|
||||||
|
keepalive?: boolean | KeepAliveProps
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control when the `NuxtPage` component is re-rendered.
|
||||||
|
*/
|
||||||
|
pageKey?: string | ((route: RouteLocationNormalizedLoaded) => string)
|
||||||
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'NuxtPage',
|
name: 'NuxtPage',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
@ -169,7 +186,24 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
}) as unknown as {
|
||||||
|
new(): {
|
||||||
|
$props: AllowedComponentProps &
|
||||||
|
ComponentCustomProps &
|
||||||
|
VNodeProps &
|
||||||
|
NuxtPageProps
|
||||||
|
|
||||||
|
$slots: {
|
||||||
|
default?: (routeProps: RouterViewSlotProps) => VNode[]
|
||||||
|
}
|
||||||
|
|
||||||
|
// expose
|
||||||
|
/**
|
||||||
|
* Reference to the page component instance
|
||||||
|
*/
|
||||||
|
pageRef: Element | ComponentPublicInstance | null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _mergeTransitionProps (routeProps: TransitionProps[]): TransitionProps {
|
function _mergeTransitionProps (routeProps: TransitionProps[]): TransitionProps {
|
||||||
const _props: TransitionProps[] = routeProps.map(prop => ({
|
const _props: TransitionProps[] = routeProps.map(prop => ({
|
||||||
|
Loading…
Reference in New Issue
Block a user