Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sequencemedia/react-router-redux-render

Render isomorphic React + React Router + Redux apps and components in Node
https://github.com/sequencemedia/react-router-redux-render

isomorphic react react-router redux render

Last synced: 2 months ago
JSON representation

Render isomorphic React + React Router + Redux apps and components in Node

Awesome Lists containing this project

README

        

# react-router-redux-render

Render isomorphic _React_ apps and components in Node.

- Using _React Router_
- With Redux

_Compatible with React Router 5._

An example implementation can be found in [react-router-pagination-io](http://github.com/sequencemedia/react-router-pagination-io.git).

## Example

In Express:

```javascript
const express = require('express')

const app = express()
const port = 3000

const {
configureStore
} = require('./path/to/store')

const store = configureStore()

const routes = require('./path/to/routes')

const {
renderToString
} = require('react-router-redux-render')

app.get('/', ({ url: { path: pathname = '/' } }, res) => res.send(renderToString(store, routes, pathname)))

app.listen(port, () => console.log(`Express ${port}`))
```

If React Router matches the `pathname` to a `` then `renderToString` returns a string.

If `renderToString` encounters an error then it throwa a `500 Internal Server Error`.

If `renderToString` cannot match the `pathname` to a `` then it throws a `404 Not Found`.

## In this package

`react-router-redux-render` exports three functions:

1. `renderToString`
2. `renderToStaticMarkup`
3. `render`

`renderToString` generates `