-
Notifications
You must be signed in to change notification settings - Fork 642
Server-side render flow : is this a good approach? #251
Comments
It will every time someone loads the page directly from the server, usually it's an initial load or for browsers that do not support
|
@Dattaya, I got the part of the redirect, indeed you're right. Now, Imagine I want to react to a |
That's an interesting approach that I'll experiment with when I have free time. What about client-side, it should be able to handle errors from api too. Are you using |
const history = browserHistory;
const store = createStore( history, global.__INITIAL_STATE__ );
store.dispatch(unserialize());
history.listen( location =>
match({ routes, location }, (error, redirectLocation, renderProps)=> {
document.body.scrollTop = 0;
store.dispatch(loadDataForComponents(renderProps))
})
);
info('First client render');
ReactDOM.render(
<Provider store={store}>
<Router history={history} routes={routes}/>
</Provider>,
mountNode
); |
Both Router and match use |
Is |
It's called whenever a route is entered. If you jump between two child nodes, that's not considering an enter event and it's not called. But if you jump to some sibling, that would be an enter event. |
Thank you guys! You just helped me to improve here. What do you think about this client-side render method? const history = browserHistory;
const store = createStore( history, global.__INITIAL_STATE__ );
store.dispatch(unserialize());
info('First client render');
ReactDOM.render(
<Provider store={store}>
<Router history={history} routes={routes} render={props => {
store.dispatch(loadDataForComponents(props));
document.body.scrollTop = 0;
return <RouterContext {...props} />
}}/>
</Provider>,
mountNode
); |
As I didn't find anyone using
react-router-redux
as the following, I was wondering, is this a good approach? I just wanted be able to load component's data and to allow my middlewares topush
andreplace
Locations.As I understand,
match
is only going to bring the matching routes, but won't keep with all the redirects, and mainly, won't trigger again my actionloadDataForComponents
, so I needed to listen history, which is supposed to be garbage-collected after the.send
callSuppose the user session has expired and it ends in a 401 request, instead simply returning the error, I want to be able to redirect to login, fetching any required data.
What do you guys think?
The text was updated successfully, but these errors were encountered: