Skip to content

Commit 6bb83ab

Browse files
authored
Merge pull request #144 from kaleido-io/nav-bug
[nav-bug] using routeAdapter
2 parents 3530459 + 2816f83 commit 6bb83ab

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/components/Router.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
import React from 'react';
17+
import React, { useMemo } from 'react';
1818
import { QueryClient, QueryClientProvider } from 'react-query';
19-
import { BrowserRouter, RouteObject, useRoutes, Route } from 'react-router-dom';
19+
import {
20+
BrowserRouter,
21+
RouteObject,
22+
useLocation,
23+
useNavigate,
24+
useRoutes,
25+
} from 'react-router-dom';
2026
import { QueryParamProvider } from 'use-query-params';
2127
import { ActivityRoutes } from '../pages/Activity/Routes';
2228
import { BlockchainRoutes } from '../pages/Blockchain/Routes';
@@ -37,10 +43,28 @@ const queryClient = new QueryClient({
3743
});
3844

3945
export const Router: () => JSX.Element = () => {
46+
const RouteAdapter = ({ children }: any) => {
47+
const navigate = useNavigate();
48+
const location = useLocation();
49+
50+
const adaptedHistory = useMemo(
51+
() => ({
52+
replace(location: any) {
53+
navigate(location, { replace: true, state: location.state });
54+
},
55+
push(location: any) {
56+
navigate(location, { replace: false, state: location.state });
57+
},
58+
}),
59+
[navigate]
60+
);
61+
return children({ history: adaptedHistory, location });
62+
};
63+
4064
return (
4165
<QueryClientProvider client={queryClient}>
4266
<BrowserRouter basename={NAV_BASENAME}>
43-
<QueryParamProvider ReactRouterRoute={Route}>
67+
<QueryParamProvider ReactRouterRoute={RouteAdapter}>
4468
<Routes />
4569
</QueryParamProvider>
4670
</BrowserRouter>

0 commit comments

Comments
 (0)