Skip to content

Commit

Permalink
[nav-bug] using routeAdapter
Browse files Browse the repository at this point in the history
Signed-off-by: David Echelberger <[email protected]>
  • Loading branch information
dechdev committed Mar 26, 2022
1 parent 3530459 commit 2816f83
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 2816f83

Please sign in to comment.