Categories
React Answers

How to use React Router without changing the URL?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *