Skip to content

Commit

Permalink
feat: support clientHistoryRouterMode
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Oct 23, 2024
1 parent 907ad01 commit 5ce75ac
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
1 change: 1 addition & 0 deletions @types/global/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IWindow {
clientPrefix?: string
microApp?: any
hashRouter: boolean
clientHistoryRouterMode: 'webHistory' | 'memoryHistory'
ssrDevInfo: any
__VALTIO_DATA__?: any
}
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-vue3/src/entry/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const clientRender = async () => {
const store = createStore()
const router = createRouter({
base: isMicro() ? window.clientPrefix : window.prefix,
hashRouter: window.hashRouter
hashRouter: window.hashRouter,
clientHistoryRouterMode: window.clientHistoryRouterMode
})
const pinia = createPinia()
setStore(store)
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue3/src/entry/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { Routes } from './combine-router'

const { store, FeRoutes } = Routes as RoutesType

export function createRouter(options: VueRouterOptions & { hashRouter?: boolean } = {}) {
export function createRouter(options: VueRouterOptions & { hashRouter?: boolean; clientHistoryRouterMode?: 'webHistory' | 'memoryHistory' } = {}) {
const base = options.base ?? '/'
const { hashRouter } = options
return create({
history: __isBrowser__ ? (hashRouter ? createWebHashHistory(base) : createWebHistory(base)) : createMemoryHistory(),
history: __isBrowser__ ? (hashRouter ? createWebHashHistory(base) : options.clientHistoryRouterMode === 'webHistory' ? createWebHistory(base) : createMemoryHistory()) : createMemoryHistory(),
routes: FeRoutes as any
})
}
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-vue3/src/entry/server-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { FeRoutes, App, layoutFetch, Layout } = Routes
const staticConfig = getStaticConfig()

const serverRender = async (ctx: ISSRContext, config: IConfig) => {
const { mode, customeHeadScript, customeFooterScript, parallelFetch, prefix, isVite, isDev, fePort, https, clientPrefix, stream, rootId, bigpipe, hashRouter, asyncGlobalData } = config
const { mode, customeHeadScript, customeFooterScript, parallelFetch, prefix, isVite, isDev, fePort, https, clientPrefix, stream, rootId, bigpipe, hashRouter, clientHistoryRouterMode, asyncGlobalData } = config
const store = createStore()
const router = createRouter()
const pinia = createPinia()
Expand All @@ -36,6 +36,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig) => {
'window.__INITIAL_PINIA_DATA__': isCsr ? {} : serialize(pinia.state.value),
'window.__USE_VITE__': isVite,
'window.prefix': `"${prefix}"`,
'window.clientHistoryRouterMode': `"${clientHistoryRouterMode}"`,
'window.clientPrefix': `"${clientPrefix ?? ''}"`,
'window.ssrDevInfo': JSON.stringify(ssrDevInfo),
'window.hashRouter': Boolean(hashRouter)
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export interface IConfig {
streamHighWaterMark?: number
asyncGlobalData?: Record<string, any>
wrapMicroScope?: boolean
clientHistoryRouterMode?: 'webHistory' | 'memoryHistory'
}

export interface proxyOptions {
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/src/server/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const loadConfig = (): IConfig => {
const moduleFileExtensions = ['.web.mjs', '.mjs', '.web.js', '.js', '.web.ts', '.ts', '.web.tsx', '.tsx', '.json', '.web.jsx', '.jsx', '.vue', '.css']
const isDev = userConfig.isDev ?? process.env.NODE_ENV !== 'production'
const fePort = userConfig.fePort ?? 8999

const clientHistoryRouterMode = 'webHistory'
const hmr = Object.assign(
{
// host: '127.0.0.1',
Expand Down Expand Up @@ -208,7 +208,8 @@ const loadConfig = (): IConfig => {
dynamicFile,
babelExtraModule,
rootId,
staticConfigPath
staticConfigPath,
clientHistoryRouterMode
},
userConfig
)
Expand Down
13 changes: 1 addition & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ce75ac

Please sign in to comment.