Skip to content

Commit ca99c5d

Browse files
committed
feat: support window.ssrRequestPath inject for memoryHistory in vue3
1 parent 044fcba commit ca99c5d

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

@types/global/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface IWindow {
1111
clientHistoryRouterMode: 'webHistory' | 'memoryHistory'
1212
ssrDevInfo: any
1313
__VALTIO_DATA__?: any
14+
ssrRequestPath?: string
1415
}
1516

1617
declare global {

packages/plugin-vue3/src/entry/client-entry.ts

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const clientRender = async () => {
3131
const pinia = createPinia()
3232
setStore(store)
3333
setPinia(pinia)
34-
3534
const create = window.__USE_SSR__ ? createSSRApp : createApp
3635

3736
if (window.__INITIAL_DATA__) {

packages/plugin-vue3/src/entry/create.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import { Routes } from './combine-router'
99
const { store, FeRoutes } = Routes as RoutesType
1010

1111
export function createRouter(options: VueRouterOptions & { hashRouter?: boolean; clientHistoryRouterMode?: 'webHistory' | 'memoryHistory' } = {}) {
12-
const base = options.base ?? '/'
13-
const { hashRouter } = options
14-
return create({
15-
history: __isBrowser__ ? (hashRouter ? createWebHashHistory(base) : options.clientHistoryRouterMode === 'memoryHistory' ? createMemoryHistory(base) : createWebHistory(base)) : createMemoryHistory(),
12+
const { clientHistoryRouterMode, hashRouter, base = '/' } = options
13+
const useClientMemoryHistory = clientHistoryRouterMode === 'memoryHistory'
14+
const routerInstance = create({
15+
history: __isBrowser__ ? (hashRouter ? createWebHashHistory(base) : useClientMemoryHistory ? createMemoryHistory(base) : createWebHistory(base)) : createMemoryHistory(),
1616
routes: FeRoutes as any
1717
})
18+
if (__isBrowser__ && useClientMemoryHistory && window.ssrRequestPath) {
19+
routerInstance.push(window.ssrRequestPath)
20+
}
21+
return routerInstance
1822
}
1923

2024
export function createStore() {

packages/plugin-vue3/src/entry/server-entry.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const serverRender = async (ctx: ISSRContext, config: IConfig) => {
3939
'window.clientHistoryRouterMode': `"${clientHistoryRouterMode}"`,
4040
'window.clientPrefix': `"${clientPrefix ?? ''}"`,
4141
'window.ssrDevInfo': JSON.stringify(ssrDevInfo),
42-
'window.hashRouter': Boolean(hashRouter)
42+
'window.hashRouter': Boolean(hashRouter),
43+
'window.ssrRequestPath': `"${path}"`
4344
})
4445
const initialData = h('script', { innerHTML })
4546
const children = bigpipe

0 commit comments

Comments
 (0)