test vite ssr
This commit is contained in:
1 parent
6725bf89ad
commit
066f94188a
20 files changed
+406
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { renderToString } from '@vue/server-renderer'
|
||||
import { escapeInject, dangerouslySkipEscape } from 'vite-plugin-ssr'
|
||||
import { createApp } from './app'
|
||||
import logoUrl from './logo.svg'
|
||||
import type { PageContext } from './types'
|
||||
import type { PageContextBuiltIn } from 'vite-plugin-ssr'
|
||||
|
||||
export { render }
|
||||
// See https://vite-plugin-ssr.com/data-fetching
|
||||
export const passToClient = ['pageProps', 'urlPathname']
|
||||
|
||||
async function render(pageContext: PageContextBuiltIn & PageContext) {
|
||||
const app = createApp(pageContext)
|
||||
const appHtml = await renderToString(app)
|
||||
|
||||
// See https://vite-plugin-ssr.com/head
|
||||
const { documentProps } = pageContext
|
||||
const title = (documentProps && documentProps.title) || 'Vite SSR app'
|
||||
const desc = (documentProps && documentProps.description) || 'App using Vite + vite-plugin-ssr'
|
||||
|
||||
const documentHtml = escapeInject`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="${logoUrl}" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="${desc}" />
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">${dangerouslySkipEscape(appHtml)}</div>
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
return {
|
||||
documentHtml,
|
||||
pageContext: {
|
||||
// We can add some `pageContext` here, which is useful if we want to do page redirection https://vite-plugin-ssr.com/page-redirection
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user