Alternative Routers
Edit this pageWhile the default router uses the browser's location.pathname
to determine the current route, you can use alternative routers to change this behavior.
This includes:
- Hash mode: Uses the hash portion of the URL to determine the current route.
- Memory mode: Keeps the history of the router in memory, useful for testing.
Hash mode
Hash mode routing uses the hash portion of the URL to manage an application's state and navigation.
Unlike the default router, the hash portion of the URL will not be handled by the server meaning this is a client-side only routing.
To use hash mode, replace the <Router />
component in the application with <HashRouter />
.
Memory mode
Unlike the default router and hash, memory router does not interact with the browser's URL. This means that while the URL in the browser's address bar will change, the router will not navigate to the new route. This gives you the ability to control the router's state and history in memory which can be useful for testing purposes.
To use memory mode, replace the <Router />
component in the application with <MemoryRouter />
: