Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Minimal example of universal route & render #232

Closed
ericelliott opened this issue Jan 22, 2016 · 17 comments
Closed

Minimal example of universal route & render #232

ericelliott opened this issue Jan 22, 2016 · 17 comments

Comments

@ericelliott
Copy link

I spent a couple solid days getting universal route & render working with redux-simple-router. For the legions of other people working on universal apps, I think it would be great to supply a minimal working example in the examples folder. =)

See also #231

I got this working in universal-react-boilerplate, but it needs a little tidying up if it's going to be used for a documentation example.

If you're looking at this for reference, please pay attention to the version, because in the future we'll strip this stuff out and replace it with react-easy-universal, which basically wrangles all these other libs together and automates this process.

@timdorr
Copy link
Member

timdorr commented Jan 22, 2016

Do you want to submit a PR? That would be most helpful 😄

@ericelliott
Copy link
Author

I would love to, but I'm afraid I already spent too much time on it, but I'll see if I can recruit somebody. =)

Updated the description to be helpful to anybody who would like to take this on.

@siawyoung
Copy link

Hey @ericelliott, I'd love to help out. Where's this description you're referring to?

@timdorr
Copy link
Member

timdorr commented Jan 24, 2016

@siawyoung He means in the initial message of this issue. The basic gist is to create a very simple example of a universally rendered application.

@ericelliott
Copy link
Author

👍

@gaearon
Copy link
Member

gaearon commented Jan 26, 2016

I’m happy to accept a PR adding react-router-redux to the universal example in Redux repo.
It’s fine if it has only one or two routes.

The only thing additional to server rendering I want to show there is preparing the store with async action by grabbing static fetchData or similar on the component. That’s a very common technique we should describe.

@robbestad
Copy link

I got some time to spare to work up a minimal example, so I'd be happy to do it. What data source is preferrable to use?

@ericelliott
Copy link
Author

@svenanders Maybe a route already available in existing examples in one of these repos?

@justin808
Copy link
Contributor

@ericelliott I've got an example with server rendering:

shakacode/react-webpack-rails-tutorial. react-router-redux including Server Rendering using React on Rails, live at www.reactrails.com.

@xulien
Copy link

xulien commented Feb 15, 2016

I just created a PR on redux repo
reduxjs/redux#1403

it's just a proposal awaiting remarks

@ivan-hilckov
Copy link

@xulien Great work! tnx

@abhijeetNmishra
Copy link

@ericelliott @gaearon i am using

const reduxRouterMiddleware = syncHistory(browserHistory);

above middle works for client side rendering. But if try to use same store on server it doesnt work.

Any help !!

@mjrussell
Copy link

@abhijeetNmishra Not sure if your comment is related to the original issue, but you are running into the fact that browserHistory doesn't exist on the server and will be undefined. Use memory history if running on the server instead.

@abhijeetNmishra
Copy link

@mjrussell

if (!client) {
    reduxRouterMiddleware = syncHistory(memoryHistory);
  } else {
    reduxRouterMiddleware = syncHistory(browserHistory);
  }

above is also not working when i am trying to create redux store.

@timdorr
Copy link
Member

timdorr commented Feb 17, 2016

I just realized this landed in master too: https://github.com/reactjs/react-router-redux/tree/master/examples/server

I think this satisfies the original issue.

@abhijeetNmishra Check out the 4.0.0 branch. It should work for SSR just fine.

@timdorr timdorr closed this as completed Feb 17, 2016
@abhijeetNmishra
Copy link

@timdorr i am gettin error:

(0 , _reactRouterRedux.routerMiddleware) is not a function

also i don't find routerMiddleware to be exported from react-router-redux file.

am i missing something for this implementation.

@timdorr
Copy link
Member

timdorr commented Feb 17, 2016

npm install --save react-router-redux@next

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants