Skip to content

Commit

Permalink
fix: routing inside search module
Browse files Browse the repository at this point in the history
  • Loading branch information
zovomat committed May 2, 2022
1 parent 9b6b615 commit b66206e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/history/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { find, startsWith, replace, trim } from 'lodash';
import { useMemo, useCallback } from 'react';
import { useLocation, useHistory } from 'react-router-dom';
import { AppRoute, HistoryParams } from '../../types';
import { SEARCH_APP_ID } from '../constants';
import { useSearchStore } from '../search/search-store';
import { useRoutes, getRoutes } from '../store/app';
import { useContextBridge } from '../store/context-bridge';

Expand All @@ -23,7 +25,14 @@ export const useCurrentRoute = (): AppRoute | undefined => {
export const getCurrentRoute = (): AppRoute | undefined => {
const history = useContextBridge.getState().functions.getHistory?.();
const routes = getRoutes();
return find(routes, (r) => startsWith(trim(history.location.pathname, '/'), r.route));
const route = find(routes, (r) => startsWith(trim(history.location.pathname, '/'), r.route));
if (route?.route === SEARCH_APP_ID) {
return {
...route,
route: `${route.route}/${useSearchStore.getState().module}`
};
}
return route;
};

export const parseParams = (params: HistoryParams): To => {
Expand Down

0 comments on commit b66206e

Please sign in to comment.