Socket
Book a DemoInstallSign in
Socket

react-routes-renderer

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

react-routes-renderer

React Routes Renderer

unpublished
latest
Source
npmnpm
Version
1.3.1
Version published
Maintainers
1
Created
Source

React.Routes.Renderer

A Promise interface for rendering isomorphic React components in Node.

An example implementation can be found in v1 of React.Router.Pagination.IO.

A companion package, redux-routes-renderer, is for React Redux applications.

Example

In your web server:

const { Renderer } = require('react-routes-renderer')

const renderer = new Renderer()

In your web server's request handler:

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

renderer.render(routes, path)
  .then((o) => {
    /*
     *  Your success response
     */
  .catch((e) => {
    /*
     *  Your failure response
     */
  })

If React Router can match the request path to a route definition and it is rendered, then your server's success response handler will receive an object which looks like:

{ rendered: /* String */ }

The rendered string will be whatever is returned from ReactDOMServer.renderToString().

If React Router matches the request path to a redirect definition, then your success response handler will receive an object which looks like:

{ redirect: /* Object */ }

The redirect object will be whatever location is returned from match().

If match() encounters an error, or ReactDOMServer.renderToString() encounters an error, then your error response handler will receive an error object; this is a 500 Internal Server Error.

If match() cannot match the request path to a route definition, then your error response handler will receive a different error; this is a 404 Not Found.

FAQs

Package last updated on 09 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts