From 21efc5c66c69711be1eef86aa35d656c5cf54bd5 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sat, 17 Jun 2023 22:55:43 +0800 Subject: [PATCH] fix(mobile-client): fix navigate is incorrect --- .../src/client/router/RouteSwitchProvider.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/plugins/mobile-client/src/client/router/RouteSwitchProvider.tsx b/packages/plugins/mobile-client/src/client/router/RouteSwitchProvider.tsx index 496ce8a4b..a452545f6 100644 --- a/packages/plugins/mobile-client/src/client/router/RouteSwitchProvider.tsx +++ b/packages/plugins/mobile-client/src/client/router/RouteSwitchProvider.tsx @@ -2,16 +2,21 @@ import { RouteSwitchProvider, useRouteSwitchContext } from '@nocobase/client'; import React, { useEffect } from 'react'; import MApplication from './Application'; import { isJSBridge } from '../core/bridge'; +import { useHistory, useLocation } from 'react-router-dom'; export const RouterSwitchProvider = (props) => { const { routes, components } = useRouteSwitchContext(); // redirect to mobile - if (isJSBridge) { - const redirectRoute = routes[0]; - if (redirectRoute.type === 'redirect' && redirectRoute.to === '/admin') { - redirectRoute.to = '/mobile'; + const location = useLocation(); + const history = useHistory(); + useEffect(() => { + if (isJSBridge) { + if (location.pathname.includes('/admin')) { + history.push('/mobile'); + } } - } + }, [history, location.pathname]); + return (