webapp/src/pages/article.page.server.ts
Igor Lobanov d37dd134b5
404 page (#151)
* 404 page

* lint

* build fix
2023-07-31 22:19:08 +02:00

22 lines
547 B
TypeScript

import type { PageContext } from '../renderer/types'
import type { PageProps } from './types'
import { apiClient } from '../utils/apiClient'
import { RenderErrorPage } from 'vite-plugin-ssr/RenderErrorPage'
export const onBeforeRender = async (pageContext: PageContext) => {
const { slug } = pageContext.routeParams
const article = await apiClient.getShoutBySlug(slug)
if (!article) {
throw RenderErrorPage({ pageContext: {} })
}
const pageProps: PageProps = { article }
return {
pageContext: {
pageProps
}
}
}