dynamic meta
This commit is contained in:
@@ -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>
|
||||
`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user