mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
23 lines
656 B
TypeScript
23 lines
656 B
TypeScript
// `usePageContext` allows us to access `pageContext` in any Vue component.
|
|
// See https://vike.dev/pageContext-anywhere
|
|
|
|
import { PageContext } from 'vike/types'
|
|
import { inject } from 'vue'
|
|
|
|
import type { App, InjectionKey } from 'vue'
|
|
|
|
export const vikePageContext: InjectionKey<PageContext> = Symbol('pageContext')
|
|
|
|
function usePageContext() {
|
|
const pageContext = inject(vikePageContext)
|
|
if (!pageContext) throw new Error('setPageContext() not called in parent')
|
|
return pageContext
|
|
}
|
|
|
|
function setPageContext(app: App, pageContext: PageContext) {
|
|
app.provide(vikePageContext, pageContext)
|
|
}
|
|
|
|
export { usePageContext }
|
|
export { setPageContext }
|