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])