Skip to content

oayres/react-ssr-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-ssr-examples

This repository aims to provide you with a reasonable base to refer to on recommended approaches for getting started with react-ssr. Generally speaking, we advise you use babel (to make use of our babel plugin) and a module bundler to produce a server bundle and client bundle. In our example we'll use Webpack.

Also, as a heads up, these examples use StandardJS, because it's beautiful. Don't be put off by the lack of semi-colons.

Generic setup

Assuming a simple Node server with Express, you'll need to instantiate react-sst and pass in any of the options listed lower down. An array of static React routes is the only thing required (you should put the array in a separate file, unlike the example...).

import express from 'express'
import ssr from 'react-ssr'
import HomePage from './HomePage'
import NotFoundPage from './NotFoundPage'

const app = express()
const renderer = ssr({
  routes: [
    {
      path: '/',
      exact: true,
      component: HomePage
    },
    {
      path: '/about',
      redirectTo: '/'
    },
    {
      path: '**',
      component: NotFoundPage
    }
  ]
})

app.get('*', renderer) // send all routes to ssr

About

Example setups for react-ssr

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published