React-router: history.listen doesn't fire when route changes via history.push

Created on 17 Jun 2019  路  4Comments  路  Source: ReactTraining/react-router

Version

5.0.0

## Test Case
-

Steps to reproduce

  1. import { withRouter, Link } from 'react-router-dom';
  2. componentDidMount() {this.unlisten = this.props.history.listen(() => console.log('route changed')); }
  3. componentWillUnmount() {this.unlisten();}
  4. this.props.history.push('url'); _in my case this line executed after ajax req_
  5. export default connect(mapStateToProps, mapDispatchToProps)(withRouter(MyCom));

Expected Behavior

console.log('route changed') should run after step 4. but it doesn't.

Actual Behavior

history.listen doesn't fire.

BTW when if route changes via <Link>, everything is fine.

Most helpful comment

@timdorr please don't close the issue without any explanation then! if this is not a bug, what is this?

All 4 comments

Please don't recreate issues.

@timdorr please don't close the issue without any explanation then! if this is not a bug, what is this?

@dehghani-mehdi This is an issue related to ReactTraining/history not to React Router.

Just for reference, for more info about this issue, see: https://github.com/ReactTraining/history/issues/710

Was this page helpful?
0 / 5 - 0 ratings