-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-router-redux's push() not rendering new route #4924
Comments
Thanks! Actually this helped me much more: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/redux.md |
I tried wrapping all my connected components with App.jsx: <Route component={Home} /> Home.jsx: class Home extends React.Component {
...
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Home)) The URL changes but the route does not render. |
The react-router-rom: 4.0.0 |
@dominikbulaj Could you share how you got your Gist example to work with the |
@danyim in my case in index.js (entry point) I've: ReactDOM.render(
<Provider store={store}>
<App>
<Router history={history}/>
</App>
</Provider>,
document.getElementById('root')
)
export default ({history}) => <ConnectedRouter history={history}>
<Switch>
<Route exact path='/' component={Home}/>
<Route path="/login" component={Login}/>
<Route path="/logout" component={Logout}/>
{* ... *}
</Switch>
</ConnectedRouter> NOTE not every comonent needs |
@dominikbulaj Thanks. We were able to figure it out. The boilerplate we were using nested a |
@dominikbulaj In the latest version of |
@viennv1709 Hmm, I'm still using it. Here's what I import in my
|
If my opinion matters to anyone, I got no luck using |
I figured out the best way to do this using react-router 4. BrowserRouter internally creates its own history object that does not work as expected. That's what was causing the problem for me. I solved it by avoiding BrowserRouter, using Router instead and creating my own history object:
And then inside MyComponent, use this to navigate to a new URL:
|
@dominikbulaj // myHistory.js
import createHistory from 'history/createBrowserHistory';
const history = createHistory();
export default history; import myHistory.js anywhere you called // example: AdminRoutes.js
import { ConnectedRouter } from 'react-router-redux';
import history from './myHistory';
import App from '../containers/AppContainer';
/////////////////////////////////// I did create here, now removed!!
//import createHistory from 'history/createBrowserHistory';
//const history = createHistory(});
///////////////////////////////////
const AdminRoutes = (props) => {
return (
<ConnectedRouter history={history}>
<App muiTheme={muiTheme} {...props} />
</ConnectedRouter>
);
} |
@josephMG no I call So my example is as follows: // index.js
import createHistory from 'history/createBrowserHistory'
import { Provider } from 'react-redux'
import configureStore from './configureStore'
// ...
const history = createHistory() // <-- createHistory() call
const store = configureStore(history) // <-- createHistory() response passed to create store
ReactDOM.render(
<Provider store={store}>
<App>
<Router history={history}/>
</App>
</Provider>,
document.getElementById('root')
) And inside // configureStore.js
import multi from 'redux-multi'
import thunkMiddleware from 'redux-thunk'
import { routerMiddleware } from 'react-router-redux'
// ...
const configureStore = (browserHistory) => {
let middleware = [
thunkMiddleware, // lets us dispatch() functions
routerMiddleware(browserHistory), // <-- here I put createHistory() response/value
multi
]
return createStore(
reducers,
applyMiddleware(
...middleware
))
}
export default configureStore |
@naderchehab's solution worked for me. Wohoo! What a day! |
@MtDalPizzol solution worked for me. Check out the video. Basically instead of using: Use:
|
@naderchehab I fixed mine like so
and in the component I did this:
it worked like a charm once i passed the history in as a prop. |
<Router history={history}>
<App>
<Switch>
<Route exact path="/" component={indexComponent} />
<Route path="/login" component={LoginView} />
<Route path="/partner" render={renderPartner} />
</Switch>
</App>
</Router> In case if someone has a code like this, it's important to use WithRouter with a parent component, for example, App. So, the parent component will be able to detect changes in location object. |
Searching on the internets I found this to be a common problem for users of React Router. More info here: remix-run/react-router#4924.
Searching on the internets I found this to be a common problem for users of React Router. More info here: remix-run/react-router#4924.
@naderchehab 's solution worked for me as well. @timdorr Is there a plan to possibly reopen this issue? We did not have any shouldComponentUpdate or PureComponents in the component tree that were affecting this issue. withRouter alone did not help, but switching from BrowserRouter to Router w/withHistory definitely worked. |
Since you guys are talking about react-router-redux is using contextTypes not the preferred solution anymore? Then you just simply call it like this: |
First of all, sorry if title is misleading.
I've problems with using react-router-redux@next with react-router-dom@4.0.0
I set up all correctly (I'm migrating from V3) and when I
dispatch(push(..))
I can see in DevTools action@@router/LOCATION_CHANGE
is triggered. Also URL changes. But components are not rendered. However it works without issues with router'sLink
Version
react-router-rom 4.0.0
react-router-redux 5.0.0-alpha.4
Steps to reproduce
I'm attaching file with simple App containing 3 stateless components and defined 3 routes. Also there're 3 links using Link component and 3 using react-router-redux' push (links to the same components). I couldn't use codepen since I haven't found react-router-redux and react-redux on cdn. Sorry!
File: https://gist.github.com/dominikbulaj/33c37099a0073278eebbba3a0226f2d2
Expected Behavior
Render components when using react-router-redux
Actual Behavior
I see action
@@router/LOCATION_CHANGE
being triggered. URL changes but nothing changes on page.Looks like it doesn't push anything to
history
object.The text was updated successfully, but these errors were encountered: