Sometimes, we want to use React Router without changing the URL.
In this article, we’ll look at how to use React Router without changing the URL.
How to use React Router without changing the URL?
To use React Router without changing the URL, we can use the MemoryRouter
component.
For instance, we write
import { MemoryRouter } from 'react-router'
<MemoryRouter>
<App/>
</MemoryRouter>
to import the MemoryRouter
component and then wrap it around App
to let us navigate with React Router without changing URLs.
Conclusion
To use React Router without changing the URL, we can use the MemoryRouter
component.