Skip to content

Commit

Permalink
Merge pull request #144 from kaleido-io/nav-bug
Browse files Browse the repository at this point in the history
[nav-bug] using routeAdapter
  • Loading branch information
dechdev authored Mar 26, 2022
2 parents 3530459 + 2816f83 commit 6bb83ab
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import React, { useMemo } from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { BrowserRouter, RouteObject, useRoutes, Route } from 'react-router-dom';
import {
BrowserRouter,
RouteObject,
useLocation,
useNavigate,
useRoutes,
} from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { ActivityRoutes } from '../pages/Activity/Routes';
import { BlockchainRoutes } from '../pages/Blockchain/Routes';
Expand All @@ -37,10 +43,28 @@ const queryClient = new QueryClient({
});

export const Router: () => JSX.Element = () => {
const RouteAdapter = ({ children }: any) => {
const navigate = useNavigate();
const location = useLocation();

const adaptedHistory = useMemo(
() => ({
replace(location: any) {
navigate(location, { replace: true, state: location.state });
},
push(location: any) {
navigate(location, { replace: false, state: location.state });
},
}),
[navigate]
);
return children({ history: adaptedHistory, location });
};

return (
<QueryClientProvider client={queryClient}>
<BrowserRouter basename={NAV_BASENAME}>
<QueryParamProvider ReactRouterRoute={Route}>
<QueryParamProvider ReactRouterRoute={RouteAdapter}>
<Routes />
</QueryParamProvider>
</BrowserRouter>
Expand Down

0 comments on commit 6bb83ab

Please sign in to comment.