How to use the history/lib/createLocation function in history

To help you get started, we’ve selected a few history 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 prescottprue / generator-react-firebase / examples / react-firebase-redux / lib / index-server.js View on Github external
export default (url, cb) => {
  const memoryHistory = createMemoryHistory(url)
  let routes = createRoutes(memoryHistory)
  let location = createLocation(url)

  match({ routes, location }, (error, redirectLocation, renderProps) => {
    if (error) console.log('Error matching', error)

    let initialData = {entities: { cars: {}, account: {} }}

    const store = configureStore(initialData, memoryHistory)

    // Grab the initial state from our Redux store
    const finalState = store.getState()

    const rootComponent = renderToString(
      
        
      
    )
github tech-dojo / react-showcase / server / routes / react-router-render.js View on Github external
app.use((req, res, next) => {
    const location = createLocation(req.path);

    // Note that req.url here should be the full URL path from
    // the original request, including the query string.
    match({
      routes,
      location
    }, (error, redirectLocation, renderProps) => {
      if (error) {
        res.status(500).send(error.message)
      } else if (redirectLocation) {
        res.redirect(302, redirectLocation.pathname + redirectLocation.search)
      } else if (renderProps) {
        renderWithData(req, res, renderProps);

      } else {
        next();
github darul75 / personal-blog / server / utils / renderer.js View on Github external
}
        }
      }
    };

    /* This is where the magic happens, we take the locals data we have already
    fetched and seed our stores with data.
    Next we use react-router to run the URL that is provided in routes.jsx
    Finally we use iso in order to render this content so it picks back up
    on the client side and bootstraps the stores.
    init server renderer
    */
    alt.bootstrap(JSON.stringify(res.locals.data || oneItemBootstraped));

    try {
      const location = createLocation(req.url);

      match({ routes, location }, (error, redirectLocation, renderProps) => {
        if (redirectLocation) {
          res.redirect(301, redirectLocation.pathname + redirectLocation.search);
        }
        else if (error) {
          res.send(500, error.message);
        }
        else if (renderProps == null) {
          res.send(404, 'Not found');
        }
        else {
          // alt flux flush
          const content = renderToString();
          iso.add(content, alt.flush());
github jermspeaks / generator-react-redux / app / templates / src / server.js View on Github external
server.get('*', (req, res, next) => {
  try {
    let statusCode = 200;

    const data = {
      title: '',
      description: '',
      css: '',
      body: '',
      debug: DEBUG,
      version: PKG_VERSION
    };
    const css = [];
    const location = createLocation(req.url);
    // const history = createHistory(req.url);

    match({ routes, location }, (error, redirectLocation, renderProps) => {
      if (redirectLocation) {
        res.redirect(301, redirectLocation.pathname + redirectLocation.search);
      } else if (error) {
        res.status(500).send(error.message);
      } else if (renderProps === null) {
        res.status(404).send('Not found');
      } else {
        data.title = 'DME';
        // data.body = renderToString();
        data.css = css.join('');
        const html = ReactDOM.renderToStaticMarkup();
        res.status(statusCode).send('\n' + html);
      }
github ascoders / isomorphic-react-redux-app / server / server.js View on Github external
app.get('/*', function (req, res) {
    const location = createLocation(req.url)

    match({routes, location}, (err, redirectLocation, renderProps) => {

            if (err) {
                console.error(err)
                return res.status(500).end('Internal server error')
            }

            if (!renderProps) {
                return res.status(404).end('Not found')
            }

            const store = configureStore()

            const InitialView = (
github coodoo / react-redux-isomorphic-example / js / boot-server.js View on Github external
function handleRouting( req, res, next ) {

	let location = createLocation( req.url );
	let store = finalCreateStore(combinedReducers);
	let childRoutes = routes( store );

	match({ routes: childRoutes, location }, ( error, redirectLocation, renderProps ) => {

		if ( redirectLocation ) {

			return res.redirect( 301, redirectLocation.pathname + redirectLocation.search );

		} else if ( error ) {

			console.log( '跑來錯: ', error)
			return res.status(500).send( error.message );

		} else if ( renderProps == null ) {
github pitzcarraldo / spring-react-redux-universal-example / client / src / server / render.js View on Github external
export default function render(req, res) {
  let user = {
    name: 'John Smith',
    dept: 'Web Team',
    lastLogin: new Date(),
    email: 'john@smith.com',
    id: 'abcde1234'
  };

  const location = createLocation(req.url);

  match({routes, location}, (err, redirectLocation, renderProps) => {
    if (err) {
      console.error(err);
      return res.status(500).end('Internal server error');
    }

    if (!renderProps) {
      return res.status(404).end('Not found');
    }

    const store = configureStore({user: user}, false);

    const InitialView = (
github caljrimmer / portfolio-redux-app / src / server / server.js View on Github external
app.get('/*', function (req, res) {

  const location = createLocation(req.url);

  match({ routes, location }, (err, redirectLocation, renderProps) => {

    if(err) {
      console.error(err);
      return res.status(500).end('Internal server error');
    }

    if(!renderProps)
      return res.status(404).end('Not found');

    const store = configureStore();

    const InitialView = (
      
        {() =>
github grommet / grommet-cms / server / isomorphicRender.js View on Github external
export default function isomorphicRender(req, res) {
  const location = createLocation(req.url);
  const authStatus = req.isAuthenticated();
  const user = (authStatus && req.user)
    ? {
      _id: req.user._id,
      username: req.user.username,
      role: (req.user.role === 0) ? 0 : 1
    } : undefined;

  const store = configureStore({
    api: {
      url: process.env.API_URL
    },
    login: {
      loggedIn: authStatus,
      loginRequest: false,
      loginError: '',
github mykhailo-riabokon / redux-form-universal-example / src / client / index.js View on Github external
/**
 * Created by mikhail on 15.09.15.
 */
import React from 'react';
import router from './routing/router.js';
import createLocation from 'history/lib/createLocation';
import createBrowserHistory from 'history/lib/createBrowserHistory';

const history = createBrowserHistory();
const location = createLocation(document.location.pathname, document.location.search);

const dist = document.getElementById('app');

router(location, history)
  .then((reactEl) => {
    React.render(reactEl, dist);
  }, (err) => {
    React.render(<p>Initial render error {err}</p>, dist);
  });