Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/roe.dev. This is the code and content for my personal website, built in Nuxt. roe.dev
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031import type { NuxtApp } from '#app'import type { RouteLocationRaw } from 'vue-router'
type StaticData = Pick<NuxtApp['payload'], 'data' | 'state'>
export default defineNuxtPlugin(nuxtApp => { const router = useRouter() const resolve = (route: string | RouteLocationRaw) => typeof route === 'string' ? route : router.resolve(route).path
const s = { prefetched: new Set<string>(), prefetch: async (route: string | RouteLocationRaw) => { const path = resolve(route)
if (!s.prefetched.has(path)) { const name = path === '/' ? '/index' : path const { data, state } = await $fetch<StaticData>(`${name}.json`) Object.assign(nuxtApp.payload.data, data) for (const item in state) { nuxtApp.payload.state[item] ??= state[item] } } }, }
return { provide: { static: s }, }})