Skip to content

Commit

Permalink
fix: prepare for react router v7
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Dec 20, 2024
1 parent cb159cf commit 43d27a1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
3 changes: 2 additions & 1 deletion packages/widget-playground-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@mui/system": "^6.2.0",
"@tanstack/react-query": "^5.62.8",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-router-dom": "^6.28.0"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
Expand Down
18 changes: 16 additions & 2 deletions packages/widget/src/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { QueryClientProvider } from '@tanstack/react-query'
import type { PropsWithChildren } from 'react'
import { Fragment } from 'react'
import { MemoryRouter, useInRouterContext } from 'react-router-dom'
import {
MemoryRouter,
type MemoryRouterProps,
useInRouterContext,
} from 'react-router-dom'
import { PageEntered } from './components/PageEntered.js'
import { queryClient } from './config/queryClient.js'
import { I18nProvider } from './providers/I18nProvider/I18nProvider.js'
Expand Down Expand Up @@ -37,12 +41,22 @@ export const AppProvider: React.FC<PropsWithChildren<WidgetConfigProps>> = ({
)
}

const memoryRouterProps: MemoryRouterProps = {
future: {
v7_startTransition: true,
v7_relativeSplatPath: true,
},
}

export const AppRouter: React.FC<PropsWithChildren> = ({ children }) => {
const { buildUrl } = useWidgetConfig()
const inRouterContext = useInRouterContext()
const Router = inRouterContext ? Fragment : MemoryRouter

const routerProps = inRouterContext ? undefined : memoryRouterProps

return (
<Router>
<Router {...routerProps}>
{children}
{buildUrl ? <URLSearchParamsBuilder /> : null}
<PageEntered />
Expand Down
Loading

0 comments on commit 43d27a1

Please sign in to comment.