From 6fe696b5ee9939f11f25d8ffdb8ab1735966b5f3 Mon Sep 17 00:00:00 2001 From: Zakary Date: Thu, 7 Jul 2022 10:34:38 +0800 Subject: [PATCH 1/2] fix(rtouer): tabbar with search fix #11917 --- packages/taro-router/src/router/page.ts | 4 ++-- packages/taro-router/src/utils.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/taro-router/src/router/page.ts b/packages/taro-router/src/router/page.ts index f13deccb3f11..d67c0937c402 100644 --- a/packages/taro-router/src/router/page.ts +++ b/packages/taro-router/src/router/page.ts @@ -9,7 +9,7 @@ import { bindPageResize } from '../events/resize' import { bindPageScroll } from '../events/scroll' import { setHistoryMode } from '../history' import { initTabbar } from '../tabbar' -import { addLeadingSlash, routesAlias, stripBasename } from '../utils' +import { addLeadingSlash, routesAlias, stripBasename, stripTrailing } from '../utils' import stacks from './stack' function setDisplay (el?: HTMLElement | null, type = '') { @@ -85,7 +85,7 @@ export default class PageHandler { } )?.[0] || routePath - return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath) + return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath) } isSamePage (page?: PageInstance | null) { diff --git a/packages/taro-router/src/utils.ts b/packages/taro-router/src/utils.ts index 8554ee31bda2..9f8e3b2f4813 100644 --- a/packages/taro-router/src/utils.ts +++ b/packages/taro-router/src/utils.ts @@ -6,6 +6,8 @@ export const hasBasename = (path = '', prefix = '') => export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substr(prefix.length) : path +export const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '') + class RoutesAlias { conf: Array = [] From 5fa352a0fe25869ebf096c5439f0ca420dd054df Mon Sep 17 00:00:00 2001 From: Zakary Date: Thu, 7 Jul 2022 14:55:29 +0800 Subject: [PATCH 2/2] fix(helper): swc-register typings --- packages/taro-helper/src/swcRegister.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/taro-helper/src/swcRegister.ts b/packages/taro-helper/src/swcRegister.ts index 74fed411eed5..a42c07cc05cf 100644 --- a/packages/taro-helper/src/swcRegister.ts +++ b/packages/taro-helper/src/swcRegister.ts @@ -16,7 +16,12 @@ export class InjectDefineConfigHeader extends Visitor { } } -export default function createSwcRegister ({ only, plugin }) { +interface ICreateSwcRegisterParam { + only + plugin? +} + +export default function createSwcRegister ({ only, plugin }: ICreateSwcRegisterParam) { const config: Record = { only: Array.from(new Set([...only])), jsc: {