diff --git a/packages/uni-app-plus/dist/uni.runtime.esm.js b/packages/uni-app-plus/dist/uni.runtime.esm.js index 6bff3c8e0a789039a5116a2ed1f5a9a2ea25e448..af2eb58c7a0d467d35567148824c062b6a95d257 100644 --- a/packages/uni-app-plus/dist/uni.runtime.esm.js +++ b/packages/uni-app-plus/dist/uni.runtime.esm.js @@ -16848,7 +16848,18 @@ function initVueApp(appVm) { const pages = []; function addCurrentPage(page) { - pages.push(page); + const $page = page.$page; + if (!$page.meta.isNVue) { + return pages.push(page); + } + // 开发阶段热刷新需要移除旧的相同 id 的 page + const index = pages.findIndex((page) => page.$page.id === page.$page.id); + if (index > -1) { + pages.splice(index, 1, page); + } + else { + pages.push(page); + } } function getPageById(id) { return pages.find((page) => page.$page.id === id); @@ -18193,15 +18204,17 @@ function registerPage({ url, path, query, openType, webview, nvuePageVm, eventCh console.log(formatLog('registerPage', path, webview.id)); } initWebview(webview, path, query, routeOptions.meta); - const route = path.substr(1); + const route = path.slice(1); webview.__uniapp_route = route; const pageInstance = initPageInternalInstance(openType, url, query, routeOptions.meta, eventChannel); const id = parseInt(webview.id); if (webview.nvue) { - if (id === 1 && nvuePageVm) { - initNVueEntryPage(webview, nvuePageVm, pageInstance); + if (nvuePageVm) { + // 首页或者开发时热刷 + initNVuePage(id, nvuePageVm, pageInstance); } else { + // 正常路由跳转 createNVuePage(id, webview, pageInstance); } } @@ -18232,18 +18245,20 @@ function initPageOptions({ meta }) { windowBottom: tabBarInstance.indexOf(meta.route) >= 0 && tabBarInstance.cover ? tabBarInstance.height : 0, }; } -function initNVueEntryPage(webview, nvuePageVm, pageInstance) { +function initNVuePage(id, nvuePageVm, pageInstance) { initPageVm(nvuePageVm, pageInstance); addCurrentPage(nvuePageVm); - // 首页是 nvue 时,在 registerPage 时,执行路由堆栈 - if (__uniConfig.splashscreen && - __uniConfig.splashscreen.autoclose && - !__uniConfig.splashscreen.alwaysShowBeforeRender) { - plus.navigator.closeSplashscreen(); + if (id === 1) { + // 首页是 nvue 时,在 registerPage 时,执行路由堆栈 + if (__uniConfig.splashscreen && + __uniConfig.splashscreen.autoclose && + !__uniConfig.splashscreen.alwaysShowBeforeRender) { + plus.navigator.closeSplashscreen(); + } + __uniConfig.onReady(function () { + navigateFinish(); + }); } - __uniConfig.onReady(function () { - navigateFinish(); - }); } function createNVuePage(pageId, webview, pageInstance) { const fakeNVueVm = { diff --git a/packages/uni-app-plus/src/service/framework/page/getCurrentPages.ts b/packages/uni-app-plus/src/service/framework/page/getCurrentPages.ts index 620d47458245699eaa390a168f145b2ee8292041..9fc0146d21fbf276d51517be37e43a46988cb81f 100644 --- a/packages/uni-app-plus/src/service/framework/page/getCurrentPages.ts +++ b/packages/uni-app-plus/src/service/framework/page/getCurrentPages.ts @@ -6,7 +6,17 @@ import { getVueApp } from '../app/vueApp' const pages: ComponentPublicInstance[] = [] export function addCurrentPage(page: ComponentPublicInstance) { - pages.push(page) + const $page = page.$page + if (!$page.meta.isNVue) { + return pages.push(page) + } + // 开发阶段热刷新需要移除旧的相同 id 的 page + const index = pages.findIndex((page) => page.$page.id === page.$page.id) + if (index > -1) { + pages.splice(index, 1, page) + } else { + pages.push(page) + } } export function getPageById(id: number) { diff --git a/packages/uni-app-plus/src/service/framework/page/register.ts b/packages/uni-app-plus/src/service/framework/page/register.ts index a5bed80fad098179a8a7e1804ee225f61c1919d9..4e3819aa8b08e1edb90bedb3a0cd7a3bb69fdccc 100644 --- a/packages/uni-app-plus/src/service/framework/page/register.ts +++ b/packages/uni-app-plus/src/service/framework/page/register.ts @@ -96,7 +96,7 @@ export function registerPage({ initWebview(webview, path, query, routeOptions.meta) - const route = path.substr(1) + const route = path.slice(1) ;(webview as any).__uniapp_route = route const pageInstance = initPageInternalInstance( @@ -110,9 +110,11 @@ export function registerPage({ const id = parseInt(webview.id!) if ((webview as any).nvue) { - if (id === 1 && nvuePageVm) { - initNVueEntryPage(webview, nvuePageVm, pageInstance) + if (nvuePageVm) { + // 首页或者开发时热刷 + initNVuePage(id, nvuePageVm, pageInstance) } else { + // 正常路由跳转 createNVuePage(id, webview, pageInstance) } } else { @@ -146,24 +148,26 @@ function initPageOptions({ meta }: UniApp.UniRoute): PageNodeOptions { } } -function initNVueEntryPage( - webview: PlusWebviewWebviewObject, +function initNVuePage( + id: number, nvuePageVm: ComponentPublicInstance, pageInstance: Page.PageInstance['$page'] ) { initPageVm(nvuePageVm, pageInstance) addCurrentPage(nvuePageVm) - // 首页是 nvue 时,在 registerPage 时,执行路由堆栈 - if ( - __uniConfig.splashscreen && - __uniConfig.splashscreen.autoclose && - !__uniConfig.splashscreen.alwaysShowBeforeRender - ) { - plus.navigator.closeSplashscreen() + if (id === 1) { + // 首页是 nvue 时,在 registerPage 时,执行路由堆栈 + if ( + __uniConfig.splashscreen && + __uniConfig.splashscreen.autoclose && + !__uniConfig.splashscreen.alwaysShowBeforeRender + ) { + plus.navigator.closeSplashscreen() + } + __uniConfig.onReady(function () { + navigateFinish() + }) } - __uniConfig.onReady(function () { - navigateFinish() - }) } function createNVuePage(