优化 404 页面请求逻辑
All checks were successful
Node.js CI / build-and-test (push) Successful in 37s

This commit is contained in:
2025-05-02 22:54:47 +08:00
parent 2f6b3524c4
commit b9c163fd06
5 changed files with 45 additions and 17 deletions

View File

@ -1,19 +1,28 @@
import { renderToWebStream, renderToString } from 'vue/server-renderer'
import { createApp } from './main'
export async function render(_url, cookies, host) {
const { app, pinia, router } = createApp()
import { createSSRRouter } from './router.js'
export async function getRoute(_url) {
const router = createSSRRouter()
await router.push(_url)
await router.isReady()
const route = router.currentRoute.value.matched[0]
const code = route.meta.code || 200
return { router, code }
}
export async function render(router, cookies, host) {
const { app, pinia } = createApp()
app.use(router)
const ctx = {
cookies,
host,
initialState: {}
}
// await new Promise((resolve) => setTimeout(resolve, 0))
const stream = renderToWebStream(app, ctx)
const initialState = ctx.initialStat
const piniaState = pinia.state.value
return { stream, initialState, piniaState }
return { stream, piniaState }
}