history.push() stopped working after upgrading to v5

Created on 16 Jun 2020  路  8Comments  路  Source: ReactTraining/history

I have recently upgraded history module from 4.10.1 to 5.0.0 and noticed thathistory.push() stopped working. After reverting it back to v4 it starts working.

Using hash history with react-router-redux

Most helpful comment

Here is the minimal code to reproduce this issue in the browser:

import React from 'react'
import { Router, Switch, Route } from 'react-router-dom'
import { createBrowserHistory } from 'history'

const history = createBrowserHistory()

export default () => (
  <Router history={history}>
    <Switch>
      <Route path="/target">
        <h2>Target</h2>
      </Route>
      <Route path="/">
        <h2>Home</h2>
        <button onClick={() => history.push('/target')}>Push</button>
      </Route>
    </Switch>
  </Router>
)

URL is changed, but it seems that no route is matched after history.push.

Downgrading to [email protected] fixed the problem.

All 8 comments

Same issue: Uncaught Could not find router reducer in state tree, it must be mounted under "router"

I am facing the same issue. Its look like there is some issue in the newest version "5.0.0" of history package. For now we can change its version to "4.10.1" which works for me.
Use bellow command for chnage history version
npm install [email protected]

Looks like a duplicate of #803

Here is the minimal code to reproduce this issue in the browser:

import React from 'react'
import { Router, Switch, Route } from 'react-router-dom'
import { createBrowserHistory } from 'history'

const history = createBrowserHistory()

export default () => (
  <Router history={history}>
    <Switch>
      <Route path="/target">
        <h2>Target</h2>
      </Route>
      <Route path="/">
        <h2>Home</h2>
        <button onClick={() => history.push('/target')}>Push</button>
      </Route>
    </Switch>
  </Router>
)

URL is changed, but it seems that no route is matched after history.push.

Downgrading to [email protected] fixed the problem.

Duplicate of #804 and #803

same thing, we are using hash router and history.push() is no longer working

@brendonco I think this issue is regarding upgrading to v5, not v6

Was this page helpful?
0 / 5 - 0 ratings