dynamic meta

This commit is contained in:
MapleLeaf
2021-12-31 13:16:00 -06:00
committed by Darius
parent ba6f9b1698
commit 6e18aac5bd
7 changed files with 52 additions and 45 deletions

View File

@@ -1,13 +1,26 @@
import { renderToString } from "react-dom/server"
import { HeadProvider } from "react-head"
import { StaticRouter } from "react-router-dom/server"
import { Root } from "./root"
import { AppRoutes } from "./routes"
import { App } from "./app"
export async function render(url: string) {
return (
<Root>
<StaticRouter location={url}>
<AppRoutes />
</StaticRouter>
</Root>
const headTags: React.ReactElement[] = []
const app = renderToString(
<StaticRouter location={url}>
<HeadProvider headTags={headTags}>
<App />
</HeadProvider>
</StaticRouter>,
)
return /* HTML */ `
<!DOCTYPE html>
<head>
${renderToString(<>{headTags}</>)}
</head>
<body>
${app}
</body>
`
}