React Router Without Changing URL

I need to have a routing that works without changing the URL .

Before implementing this on my own, I tried to find something using a router. I saw that there is such a thing called createMemoryHistory :

createMemoryHistory ([parameters])

createMemoryHistory creates a history object in memory that does not interact with the browser URL. This is useful when you need to configure a history object used for server-side rendering, for automatic testing, or when you do not want to manipulate the browser URL, for example, when your application is embedded in an iframe.

But outside this paragraph there are no examples of use, and I can not find it for use anywhere, for example: how to use the Link component to navigate without a path name, which parameter I route if not a path, etc.

Is this right for my needs, or do I need to implement a router myself?

+5
source share
2 answers

MemoryHistory is a "history provider" that you can provide a React Router as follows:

 const memoryHistory = createMemoryHistory(options); // In your Router configuration <Router history={memoryHistory} routes={routes} /> 

Apart from the initial configuration, everything else should work just like with a normal browser history.

This article describes how to use different providers with React Router: Histories.

+8
source
+1
source

All Articles