From 2abdf026e336a5155152df59c9aea2412eb6c27d Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 11 May 2021 20:43:11 +0800 Subject: [PATCH] fix(h5): router --- packages/playground/ssr/yarn.lock | 16 ++++++++-------- packages/uni-h5-vue/dist/vue.runtime.cjs.js | 2 ++ packages/uni-h5-vue/dist/vue.runtime.esm.js | 2 +- packages/uni-h5/dist/uni-h5.cjs.js | 6 +++++- packages/uni-h5/dist/uni-h5.es.js | 6 +++++- packages/uni-h5/src/framework/plugin/router.ts | 10 +++++++--- packages/vite-plugin-uni/src/config/build.ts | 6 ++---- packages/vite-plugin-uni/src/config/index.ts | 3 +-- 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/packages/playground/ssr/yarn.lock b/packages/playground/ssr/yarn.lock index 53fcb60f64..2a9082f588 100644 --- a/packages/playground/ssr/yarn.lock +++ b/packages/playground/ssr/yarn.lock @@ -863,10 +863,10 @@ end-of-stream@^1.1.0: dependencies: once "^1.4.0" -esbuild@^0.9.3: - version "0.9.7" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.9.7.tgz#ea0d639cbe4b88ec25fbed4d6ff00c8d788ef70b" - integrity sha512-VtUf6aQ89VTmMLKrWHYG50uByMF4JQlVysb8dmg6cOgW8JnFCipmz7p+HNBl+RR3LLCuBxFGVauAe2wfnF9bLg== +esbuild@^0.11.19: + version "0.11.20" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.11.20.tgz#7cefa1aee8b372c184e42457885f7ce5d3e62a1e" + integrity sha512-QOZrVpN/Yz74xfat0H6euSgn3RnwLevY1mJTEXneukz1ln9qB+ieaerRMzSeETpz/UJWsBMzRVR/andBht5WKw== escalade@^3.1.1: version "3.1.1" @@ -2450,11 +2450,11 @@ verror@1.10.0: extsprintf "^1.2.0" vite@^2.2.3: - version "2.2.4" - resolved "https://registry.yarnpkg.com/vite/-/vite-2.2.4.tgz#8f9cc85aacab04c850085894b086c8717f12ed16" - integrity sha512-vnIwSNci+phFMp6krhy+FbYzKL0R67Sdt9mVZ96S27AewrApSJjTqncJcalk8sf60BgcbW4+1C6DFIWkxquO9g== + version "2.3.0" + resolved "https://registry.yarnpkg.com/vite/-/vite-2.3.0.tgz#02b007c7aa4ac88cc18f854b9c68e4fbe76e3ef4" + integrity sha512-gsCy0t3X9nGGYDoNiE2NJgYq6BPxrtKeo6FkpMXdMvtUluYxnRhl7xfpHaYDmQLCnMbYTWhvWS1L/Hpw/V9L5w== dependencies: - esbuild "^0.9.3" + esbuild "^0.11.19" postcss "^8.2.1" resolve "^1.19.0" rollup "^2.38.5" diff --git a/packages/uni-h5-vue/dist/vue.runtime.cjs.js b/packages/uni-h5-vue/dist/vue.runtime.cjs.js index f8c171da55..3fbcca232f 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.cjs.js +++ b/packages/uni-h5-vue/dist/vue.runtime.cjs.js @@ -9884,6 +9884,8 @@ exports.markRaw = markRaw; exports.mergeProps = mergeProps; exports.nextTick = nextTick; exports.onActivated = onActivated; +exports.onBeforeActivate = onBeforeActivate; +exports.onBeforeDeactivate = onBeforeDeactivate; exports.onBeforeMount = onBeforeMount; exports.onBeforeUnmount = onBeforeUnmount; exports.onBeforeUpdate = onBeforeUpdate; diff --git a/packages/uni-h5-vue/dist/vue.runtime.esm.js b/packages/uni-h5-vue/dist/vue.runtime.esm.js index fb5734b733..003b5ab749 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.esm.js +++ b/packages/uni-h5-vue/dist/vue.runtime.esm.js @@ -9894,4 +9894,4 @@ const compile$1 = () => { } }; -export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compatUtils, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; +export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compatUtils, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 6fc4888482..0d52fc7f5d 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -1150,8 +1150,12 @@ function createRouterOptions() { }; } function initHistory() { + let {base} = __uniConfig.router; + if (base === "/") { + base = ""; + } { - return vueRouter.createMemoryHistory(__uniConfig.router.base); + return vueRouter.createMemoryHistory(base); } } var index$s = { diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 87290fa0b5..a4dbdb3b94 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -4670,7 +4670,11 @@ function removeCurrentPages(delta = 1) { } } function initHistory() { - const history2 = __UNI_FEATURE_ROUTER_MODE__ === "history" ? createWebHistory(__uniConfig.router.base) : createWebHashHistory(__uniConfig.router.base); + let {base} = __uniConfig.router; + if (base === "/") { + base = ""; + } + const history2 = __UNI_FEATURE_ROUTER_MODE__ === "history" ? createWebHistory(base) : createWebHashHistory(base); history2.listen((_to, _from, info) => { if (info.direction === "back") { removeCurrentPages(Math.abs(info.delta)); diff --git a/packages/uni-h5/src/framework/plugin/router.ts b/packages/uni-h5/src/framework/plugin/router.ts index a5e1eecb8e..3675aa2219 100644 --- a/packages/uni-h5/src/framework/plugin/router.ts +++ b/packages/uni-h5/src/framework/plugin/router.ts @@ -45,13 +45,17 @@ function removeCurrentPages(delta: number = 1) { } function initHistory() { + let { base } = __uniConfig.router + if (base === '/') { + base = '' + } if (__NODE_JS__) { - return createMemoryHistory(__uniConfig.router.base) + return createMemoryHistory(base) } const history = __UNI_FEATURE_ROUTER_MODE__ === 'history' - ? createWebHistory(__uniConfig.router.base) - : createWebHashHistory(__uniConfig.router.base) + ? createWebHistory(base) + : createWebHashHistory(base) history.listen((_to, _from, info) => { if (info.direction === 'back') { removeCurrentPages(Math.abs(info.delta)) diff --git a/packages/vite-plugin-uni/src/config/build.ts b/packages/vite-plugin-uni/src/config/build.ts index a55b8a2552..80a4788176 100644 --- a/packages/vite-plugin-uni/src/config/build.ts +++ b/packages/vite-plugin-uni/src/config/build.ts @@ -2,15 +2,13 @@ import path from 'path' import slash from 'slash' import { UserConfig } from 'vite' import { VitePluginUniResolvedOptions } from '..' -import { FEATURE_DEFINES, initEasycomsOnce } from '../utils' +import { initEasycomsOnce } from '../utils' export function createBuild( - options: VitePluginUniResolvedOptions, - features: FEATURE_DEFINES + options: VitePluginUniResolvedOptions ): UserConfig['build'] { initEasycomsOnce(options.inputDir, options.platform) return { - polyfillDynamicImport: features.__UNI_FEATURE_PAGES__, rollupOptions: { output: { chunkFileNames(chunkInfo) { diff --git a/packages/vite-plugin-uni/src/config/index.ts b/packages/vite-plugin-uni/src/config/index.ts index 947e8695d1..bda6fd9616 100644 --- a/packages/vite-plugin-uni/src/config/index.ts +++ b/packages/vite-plugin-uni/src/config/index.ts @@ -11,7 +11,6 @@ import { createServer } from './server' import { createBuild } from './build' import { createOptimizeDeps } from './optimizeDeps' import { createDefine } from './define' -import { FEATURE_DEFINES } from '../utils' function normalizeRoot(config: UserConfig) { return normalizePath(config.root ? path.resolve(config.root) : process.cwd()) @@ -34,7 +33,7 @@ export function createConfig( resolve: createResolve(options, config), optimizeDeps: createOptimizeDeps(options), server: createServer(options), - build: createBuild(options, define as FEATURE_DEFINES), + build: createBuild(options), css: createCss(options), } } -- GitLab