From 61d71899db5c14313eb2c31ea23172d277106af5 Mon Sep 17 00:00:00 2001 From: goodmice Date: Thu, 6 Oct 2022 15:14:44 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=20=D1=81=D0=B1?= =?UTF-8?q?=D1=80=D0=BE=D1=81=20=D0=BF=D1=83=D1=82=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B5=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F/=D0=BA=D1=83=D1=81=D1=82=D0=B0/=D1=81=D0=BA=D0=B2=D0=B0?= =?UTF-8?q?=D0=B6=D0=B8=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/selectors/WellTreeSelector.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/selectors/WellTreeSelector.tsx b/src/components/selectors/WellTreeSelector.tsx index ee06e1d..55fbc67 100755 --- a/src/components/selectors/WellTreeSelector.tsx +++ b/src/components/selectors/WellTreeSelector.tsx @@ -99,6 +99,8 @@ export const WellTreeSelector = memo(({ show, expand, cur const navigate = useNavigate() const location = useLocation() + console.log(location.pathname) + useEffect(() => { if (current) setSelected([current]) }, [current]) @@ -156,7 +158,17 @@ export const WellTreeSelector = memo(({ show, expand, cur }, [wellsTree]) const onSelect = useCallback((value: Key[]): void => { - navigate(String(value), { state: { from: location.pathname }}) + const newRoot = /\/(\w+)\/(\d+)/.exec(String(value)) + const oldRoot = /\/(\w+)\/(\d+)/.exec(location.pathname) + if (!newRoot || !oldRoot) return + + let newPath = newRoot[0] + if (oldRoot[1] === newRoot[1]) { /// Если типы страниц одинаковые (deposit, cluster, well) + const url = location.pathname.substring(oldRoot[0].length) + newPath = newPath + url + } + + navigate(newPath, { state: { from: location.pathname }}) }, [navigate, location]) useEffect(() => onChange(location.pathname), [onChange, location])