From c2a587434baeb9bbe4421718c353a8d4b3aadbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com> Date: Mon, 18 Mar 2024 09:27:50 +0800 Subject: [PATCH] fix: getCurrentPages(...).at is not a function --- src/utils/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 90d3637..a6f8265 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -9,7 +9,8 @@ export const getIsTabbar = () => { return false } const pages = getCurrentPages() - const currPath = pages.at(-1).route + const lastPage = getArrElementByIdx(pages, -1) + const currPath = lastPage.route return !!pagesJson.tabBar.list.find((e) => e.pagePath === currPath) } @@ -24,3 +25,9 @@ export const testI18n = () => { content: t('app.name'), }) } + +export const getArrElementByIdx = (arr: any[], index: number) => { + if (index < 0) return arr[arr.length + index] + if (index >= arr.length) return undefined + return arr[index] +}