Skip to content

Using element with createMemoryRouter #10386

Closed Answered by brophdawg11
yuki2006 asked this question in Q&A
Discussion options

You must be logged in to vote

As long as your components aren't using any DOM-specific aspects then you should be able to just replace createBrowserRouter with createMemoryRouter directly, and pass initialEntries in the second parameter:

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by MichaelDeBoey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants