supasate / connected-react-router

A Redux binding for React Router v4
MIT License
4.73k stars 593 forks source link

code dispatch(push('/xxx')), url changes , but route not yet #417

Open R10burning opened 4 years ago

R10burning commented 4 years ago

import React, { Component } from 'react' import { connect } from 'react-redux' import { test } from '@/actions/common' import store from '@/store' import { push } from 'connected-react-router' import PropTypes from 'prop-types' @connect((state) => ({ home: state.home }), { test }) class Home extends Component { static propTypes = { test: PropTypes.func.isRequired } componentDidMount() {} toUrl = (e) => { e.stopPropagation() store.dispatch(push('/about')) } render() { return ( <div onClick={() => this.props.test()}>

go
  </div>
)

} }

export default Home

dependencies : "connected-react-router": "^6.8.0", "core-js": "2", "history": "^4.10.1", "react": "^16.13.1", "react-dom": "^16.13.1", "react-redux": "^7.2.0", "react-router-dom": "^5.1.2", "react-router-redux": "^4.0.8", "redux": "^4.0.5", "redux-actions": "^2.6.5", "redux-logger": "^3.0.6", "redux-saga": "^1.1.3"

velcis commented 4 years ago

EDIT: got it removing in the Routes.

me the same!!

muhammedsuhair74 commented 3 years ago

EDIT: got it removing in the Routes.

me the same!!

"got it removing in the Routes" sorry i didn't understand,have you solved it?

velcis commented 3 years ago

EDIT: got it removing in the Routes. me the same!!

"got it removing in the Routes" sorry i didn't understand,have you solved it?

I had an external "routes component", with another inside, you need just to use the ConnectedRouter, without the Router.

tibic commented 3 years ago

同样的问题

low-ghost commented 3 years ago

For anyone who happens to land here, @velcis is saying

<Provider store={store}>
  <ConnectedRouter history={history}>
    <Router>
      <App />
    </Router>
  </ConnectedRouter>
</Provider>

should be

<Provider store={store}>
  <ConnectedRouter history={history}>
    <App />
  </ConnectedRouter>
</Provider>

which was hella hard to track down. Not sure if the nested Router is entirely unintended or vestigial of an older version's intended setup, but killing it fixes the issue of URL changing on <Link to="/path" /> or useHistory().push("/path") but the app not registering or rendering any changes