Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where's hashHistory in React Router v4?

I'm trying to use a router for my React application. I tried something I'd been using a while back, but can't seem to get it going. Has hashHistory been removed/reformatted in React Router v4?

<Router history={hashHistory}>
  <Route path='/' component={MainContainer} />
</Router>
like image 820
Petter Östergren Avatar asked Sep 02 '17 17:09

Petter Östergren


People also ask

What are the components of react router v4?

The 'react-router' library is now split into three separate packages. react-router-dom: Designed for web applications. react-router-native: Designed for mobile applications. react-router-core: Can be used anywhere for core applications.

How do I get the previous path in react V6 router?

Currently, Im using router V6 and if you need to get a previous path. import {useLocation, useNavigate} from 'react-router-dom'; // in your component let navigate = useNavigate (); let location = useLocation (); // then check if there is previous path .. if not proceed to your default path ..


1 Answers

Use a HashRouter. They got rid of individual histories such as browserHistory and hashHistory and instead replaced them with BrowserRouter and HashRouter components respectively in React Router v4:

import { HashRouter } from 'react-router-dom';

<HashRouter>
  …
</HashRouter>

Note that HashRouter comes from react-router-dom, not the core react-router package.

like image 117
Andrew Li Avatar answered Sep 28 '22 01:09

Andrew Li