webapp/src/pages/topic.page.server.ts

25 lines
518 B
TypeScript
Raw Normal View History

import type { PageProps } from './types'
2023-02-17 09:21:02 +00:00
import type { PageContext } from '../renderer/types'
2023-11-18 15:20:15 +00:00
import { render } from 'vike/abort'
2023-02-17 09:21:02 +00:00
import { apiClient } from '../utils/apiClient'
export const onBeforeRender = async (pageContext: PageContext) => {
const { slug } = pageContext.routeParams
const topic = await apiClient.getTopic({ slug })
2023-11-18 15:20:15 +00:00
if (!topic) {
throw render(404)
}
const pageProps: PageProps = { topic, seo: { title: topic.title } }
2023-02-17 09:21:02 +00:00
return {
pageContext: {
pageProps,
},
2023-02-17 09:21:02 +00:00
}
}