From fec03fe3fd95b82ce493e63197accda4bfa24e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E5=AD=94=E6=B3=89?= Date: Thu, 9 Mar 2023 10:38:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E6=B7=BB=E5=8A=A0quer?= =?UTF-8?q?y=E5=8F=82=E6=95=B0=E7=9A=84=E6=97=B6=E5=80=99ID=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BC=82=E5=B8=B8=EF=BC=8C=E4=BD=BF=E7=94=A8=E5=89=8D?= =?UTF-8?q?=E7=BD=AE=E5=AE=88=E5=8D=AB=E6=8A=8A=E5=A4=96=E9=83=A8=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=8F=82=E6=95=B0=E6=94=BE=E5=85=A5window.route.param?= =?UTF-8?q?s=EF=BC=8C=E5=90=8E=E7=BB=ADAPI=E5=8A=A8=E6=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=AF=E4=BB=A5=E6=8B=BC=E6=8E=A5=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://localhost:3000/#/chart/preview/792622755697790976?t=123 动态请求参数中使用javascript: return window.route?.params?.t --- src/router/router-guards.ts | 7 +++++++ src/utils/router.ts | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/router/router-guards.ts b/src/router/router-guards.ts index aedb0667..7d2a885d 100644 --- a/src/router/router-guards.ts +++ b/src/router/router-guards.ts @@ -5,6 +5,13 @@ import { loginCheck } from '@/utils' export function createRouterGuards(router: Router) { // 前置 router.beforeEach(async (to, from, next) => { + // http://localhost:3000/#/chart/preview/792622755697790976?t=123 + // 把外部动态参数放入window.route.params,后续API动态接口可以用window.route?.params?.t来拼接参数 + // @ts-ignore + if (!window.route) window.route = {params: {}} + // @ts-ignore + Object.assign(window.route.params, to.query) + const Loading = window['$loading']; Loading && Loading.start(); const isErrorPage = router.getRoutes().findIndex((item) => item.name === to.name); diff --git a/src/utils/router.ts b/src/utils/router.ts index f2a9c696..ea17d78a 100644 --- a/src/utils/router.ts +++ b/src/utils/router.ts @@ -159,7 +159,8 @@ export const fetchRouteParams = () => { */ export const fetchRouteParamsLocation = () => { try { - return document.location.hash.split('/').pop() || '' + // 防止添加query参数的时候,解析ID异常 + return document.location.hash.split('?')[0].split('/').pop() || '' } catch (error) { window['$message'].warning('查询路由信息失败,请联系管理员!') return '' @@ -190,4 +191,4 @@ export const loginCheck = () => { } catch (error) { return false } -} \ No newline at end of file +} \ No newline at end of file