This commit is contained in:
@ -1,8 +1,13 @@
|
||||
import { decompress } from 'compress-json'
|
||||
import './main.css'
|
||||
import { createApp } from './main'
|
||||
|
||||
const { app, pinia, router } = createApp()
|
||||
import { createApp } from './main'
|
||||
import { createSSRRouter } from './router.js'
|
||||
|
||||
const { app, pinia } = createApp()
|
||||
const router = createSSRRouter()
|
||||
|
||||
app.use(router)
|
||||
|
||||
if (window.__PINIA_STATE__) {
|
||||
pinia.state.value = decompress(window.__PINIA_STATE__)
|
||||
|
@ -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 }
|
||||
}
|
||||
|
||||
|
@ -2,19 +2,16 @@ import { createSSRApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
import App from './App.vue'
|
||||
import { createSSRRouter } from './router.js'
|
||||
|
||||
import ClientOnly from './ssr/ClientOnly.vue'
|
||||
import Hr from './ui/BetterHr.vue'
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
const router = createSSRRouter()
|
||||
const pinia = createPinia()
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app
|
||||
.component('ClientOnly', ClientOnly)
|
||||
.component('Hr', Hr)
|
||||
return { app, pinia, router }
|
||||
return { app, pinia }
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ export function createSSRRouter() {
|
||||
component: () => import('./views/fallback/NotFound.vue'),
|
||||
meta: {
|
||||
title: "页面未找到",
|
||||
hidden: true
|
||||
hidden: true,
|
||||
code: 404
|
||||
}
|
||||
}
|
||||
]})
|
||||
|
Reference in New Issue
Block a user