How to use the react-router-dom.StaticRouter function in react-router-dom

To help you get started, we’ve selected a few react-router-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jedireza / aqua / server / web / main / index.js View on Github external
'use strict';
const React = require('react');
const ReactDomServer = require('react-dom/server');
const ReactHelmet = require('react-helmet');
const ReactRouter = require('react-router-dom');


const internals = {};
const StaticRouter = ReactRouter.StaticRouter;


internals.routeHandler = function (request, reply) {

    const routerState = {};
    const routerProps = {
        location: request.url.path,
        context: routerState
    };
    const AppUniversal = require('../../../client/pages/main/app-universal.jsx');
    const AppEl = React.createElement(AppUniversal);
    const App = React.createElement(StaticRouter, routerProps, AppEl);
    const markup = ReactDomServer.renderToString(App);
    const helmet = ReactHelmet.Helmet.renderStatic(); // leaks if not called after render

    if (routerState.url) {
github lbryio / spee.ch / server / render / build / handlePageRender.js View on Github external
sagaMiddleware.run(saga).done.then(function () {
    // render component to a string
    var html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, {
      store: store
    }, _react.default.createElement(_reactRouterDom.StaticRouter, {
      location: req.url,
      context: context
    }, _react.default.createElement(_GAListener.default, null, _react.default.createElement(_app.default, null))))); // get head tags from helmet

    var helmet = _reactHelmet.default.renderStatic(); // check for a redirect


    if (context.url) {
      return res.redirect(301, context.url);
    } // get the initial state from our Redux store


    var preloadedState = store.getState(); // send the rendered page back to the client

    res.send((0, _renderFullPage.default)(helmet, html, preloadedState));
  });
github FFF-team / earth-scripts / server / html / index.js View on Github external
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const StaticRouter = require('react-router-dom').StaticRouter;
// const multiStream = require('multistream');
// const stringStream = require('string-to-stream');
const Loadable = require('react-loadable');

// const cheerio = require('cheerio');
// const readFile = require('../util/readFile').readFile;
const getAppForPage = require('./getAppForPage');
// const pageStream = require('../util/stream');
const logger = require('../lib/logger');
const maxMem = require('../def').maxMem;
const getInitialData = require('./getInitialData');
const enhanceApp = require('./enhanceApp');
const getScripts = require('../util/getScripts');
const getCss = require('../util/getCss');
const { matchRoutes, getRouteInitialData } = require('../util/parseRoute');
const getTpl = require('./getTplForPage')
github fluidtrends / chunky / web / lib / core / App.js View on Github external
value: function renderStatic() {
      return _react2.default.createElement(
        _reactRouterDom.StaticRouter,
        {
          location: this.props.route.location,
          context: this.props.route
        },
        _react2.default.createElement(
          'div',
          null,
          this.routes
        )
      );
    }
  }, {
github Asing1001 / movieRater.React / dist / server.js View on Github external
app.use(basicCache, function (req, res, next) {
    global.navigator = { userAgent: req.headers['user-agent'] };
    global.document = {
        title: "Movie Rater",
        meta: {
            description: "蒐集了IMDB, YAHOO, PTT的電影評價,一目了然讓你不再踩雷",
            image: "/public/favicons/android-chrome-384x384.png"
        }
    };
    const client = new react_apollo_1.ApolloClient({
        ssrMode: true,
        networkInterface: apollo_local_query_1.createLocalInterface(graphql, schema_1.default),
    });
    const context = {};
    const app = (React.createElement(react_apollo_1.ApolloProvider, { client: client },
        React.createElement(react_router_dom_1.StaticRouter, { location: req.url, context: context },
            React.createElement(app_1.default, null))));
    react_apollo_1.renderToStringWithData(app).then(content => {
        const initialState = { apollo: client.getInitialState() };
        const page = swig.renderFile(staticRoot + 'bundles/index.html', {
            title: global.document.title,
            meta: global.document.meta,
            html: content,
            apolloState: ``
        });
        res.status(context["status"] || 200).send(page);
    }, error => next(error));
});
app.use(function (err, req, res, next) {
github Houfeng / doczilla / src / common / router.js View on Github external
import conf from '$config';

//计算 conf
const defConf = { mode: 'hash', baseUri: '', extname: '.html' };
const docConf = (() => {
  const { mode, baseUri } = (global.DOC_DATA || {});
  return { mode, baseUri };
})();
const routeConf = Object.assign(defConf, conf.router, docConf, global.router);
if (conf.env === 'dev') Object.assign(routeConf, conf.router);

const Switch = rd.Switch;
const Router = {
  hash: rd.HashRouter,
  browser: rd.BrowserRouter,
  static: rd.StaticRouter,
}[routeConf.mode] || rd.HashRouter;

const Route = {
  hash: rd.Route,
  static: rd.Route,
  browser: props => {
    const { path, children, ...others } = props;
    const { baseUri } = routeConf;
    return 
      {children}
    ;
  },
}[routeConf.mode] || rd.Route;

const Link = {
  hash: rd.Link,
github joe-sky / nornj / packages / nornj-react / dist / nornj-react-router.js View on Github external
var _nornj = require("nornj");

  var _reactRouterDom = require("react-router-dom");

  (0, _nornj.registerComponent)({
    BrowserRouter: _reactRouterDom.BrowserRouter,
    HashRouter: _reactRouterDom.HashRouter,
    'router-Link': _reactRouterDom.Link,
    MemoryRouter: _reactRouterDom.MemoryRouter,
    'router-NavLink': _reactRouterDom.NavLink,
    'router-Prompt': _reactRouterDom.Prompt,
    Redirect: _reactRouterDom.Redirect,
    Route: _reactRouterDom.Route,
    Router: _reactRouterDom.Router,
    StaticRouter: _reactRouterDom.StaticRouter,
    'router-Switch': _reactRouterDom.Switch
  });

})));
github Chainers / steepshot-web / configs / utils.js View on Github external
var path = require("path");
var renderToString = require("react-dom/server").renderToString;
var React = require("react");
var StaticRouter = require("react-router-dom").StaticRouter;
var lib = require("./lib");

var httpCodes = {
	redirect: 301,
	ok: 200,
	notFound: 404,
	internalServerError: 500,
	notImplemented: 501
};

var pollInterval = 200;

function isRedirect(res) {
	return res.statusCode === httpCodes.redirect;
}
github btholt / complete-intro-to-react / server.js View on Github external
require('babel-register');

const express = require('express');
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const ReactRouter = require('react-router-dom');
const _ = require('lodash');
const fs = require('fs');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const compression = require('compression');
const webpack = require('webpack');
const config = require('./webpack.config');
const App = require('./js/App').default;

const StaticRouter = ReactRouter.StaticRouter;
const port = 8080;
const baseTemplate = fs.readFileSync('./index.html');
const template = _.template(baseTemplate);

const server = express();
server.use(compression());
if (process.env.NODE_ENV === 'development') {
  const compiler = webpack(config);
  server.use(
    webpackDevMiddleware(compiler, {
      publicPath: config.output.publicPath
    })
  );
  server.use(webpackHotMiddleware(compiler));
}
server.use('/public', express.static('./public'));
github dive2Pro / SoundCloudMobx / src / components / Player / __Playser.spec.tsx View on Github external
import * as React from 'react'
import Player from './index'
import { shallow, mount } from 'enzyme';
import toJson from 'enzyme-to-json';
import { playerStore,performanceStore } from '../../store';
import ButtonInline from '../ButtonInline'
import {Provider} from "mobx-react";
const StaticRouter = require("react-router-dom").StaticRouter;
describe('Player Component', () => {
  let track: any = {
    id: 1234,
    title: 'hohohoho',
    user: {

    }
  }

  let props = {
    playerStore,
    performanceStore,
  }

  let wrapper