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.
12345678910111213141516171819202122232425262728293031export default defineNuxtPlugin(nuxtApp => { const router = useRouter()
router.getRoutes().forEach(route => { router.addRoute({ path: (route.path === '/' ? '/index' : route.path) + '.json', components: route.components, }) })
nuxtApp.hook('app:rendered', ctx => { if (ctx.ssrContext.url.endsWith('.json')) { const res = ctx.ssrContext.res res.setHeader('Content-Type', 'application/json') res.end( JSON.stringify({ data: nuxtApp.payload.data, state: { ...nuxtApp.payload.state, '$scolor-mode': undefined, $serror: undefined, }, }) ) } else { const url = ctx.ssrContext.url === '/' ? '/index' : ctx.ssrContext.url ctx.html.head.push(`<!-- <link rel="prefetch" href="${url}.json"> -->`) } })})