Using element with createMemoryRouter #10386
-
Thank you for providing such a useful library. const router = createBrowserRouter([
{
path: '/',
element: (
<QueryParamProvider>
<Outlet />
</QueryParamProvider>
),
children: layoutChildren,
},
]); I'm looking for a way to achieve a similar configuration using createMemoryRouter. Any guidance would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As long as your components aren't using any DOM-specific aspects then you should be able to just replace const router = createMemoryRouter([
{
path: '/',
element: (
<QueryParamProvider>
<Outlet />
</QueryParamProvider>
),
children: layoutChildren,
},
], {
initialEntries: ['/whatever'],
}); If your components use DOM-specific aspects then you will need to find a way to abstract them away and inject them based on the environment you are running in. |
Beta Was this translation helpful? Give feedback.
As long as your components aren't using any DOM-specific aspects then you should be able to just replace
createBrowserRouter
withcreateMemoryRouter
directly, and passinitialEntries
in the second parameter:If your components use DOM-specific aspects then you will need to find a way to abstract them away and inject them based on the environment you are running in.