How to use the history/lib/createMemoryHistory 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 shalomeir / snippod-boilerplate / snippod-webapp / src / server.js View on Github external
app.use((req, res) => {
  if (__DEVELOPMENT__) {
    // Do not cache webpack stats: the script file would change since
    // hot module replacement is enabled in the development env
    webpackIsomorphicTools.refresh();
  }
  const client = new ApiClient(req);
  const history = createHistory();

  const store = createStore(getRoutes, history, client);

  function hydrateOnClient() {
    res.send('\n' +
      ReactDOM.renderToString());
  }

  if (__DISABLE_SSR__) {
    hydrateOnClient();
    return;
  }

  match({ history, routes: getRoutes(store), location: req.originalUrl }, (error, redirectLocation, renderProps) => {
    if (redirectLocation) {
      res.redirect(redirectLocation.pathname + redirectLocation.search);
github zapier / redux-router-kit / test / components / History.js View on Github external
test('History changes when new url is passed to history', t => {
  const node = document.createElement('div');
  document.body.appendChild(node);
  const history = createMemoryHistory();
  const onChangeSpy = sinon.spy();
  const onLocationChangeSpy = sinon.spy();
  render(
    ,
    node
  );
  history.listen(onLocationChangeSpy);
  render(
    ,
    node
  );
  t.false(onChangeSpy.called);
  t.true(onLocationChangeSpy.called);
  t.is(onLocationChangeSpy.lastCall.args[0].pathname, '/hello');
});
github FormidableLabs / redux-little-router / test / initial-router-state.spec.js View on Github external
it('provides the correct routes and query strings for the initial state', () => {
    const history = createMemoryHistory();
    sandbox.stub(history, 'createLocation').returns({
      pathname: '/home/messages/b-team',
      search: '?test=ing',
      query: {
        test: 'ing'
      }
    });

    const initialState = initialRouterState({
      history,
      routes: {},
      pathname: '/home/messages/b-team',
      query: {
        test: 'ing'
      }
    });
github nfl / react-metrics / test / ReactMetrics / willTrackPageView.spec.js View on Github external
componentWillReceiveProps() {
                componentWillReceivePropsCalled = true;
            }

            componentDidUpdate() {
                componentDidUpdateCalled = true;
            }

            render() {
                return <h3>Content</h3>;
            }
        }

        ReactDOM.render(
            
                
                    
                        
                    
                
            ,
            node,
            function() {
                this.history.pushState(null, "/page/content2");
            }
        );
    });
github nfl / react-metrics / test / ReactMetrics / exposeMetrics.spec.js View on Github external
}

        @exposeMetrics()
        class Page extends React.Component {
            static willTrackPageView() {
                expect(true).to.be.ok;
                done();
            }

            render() {
                return <h1>Page</h1>;
            }
        }

        ReactDOM.render(
            
                
                    
                
            ,
            node,
            function() {
                this.history.pushState(null, "/page/1");
            }
        );
    });
github blockstack / blockstack.org / _old / utils / testHelpers.js View on Github external
_.merge(props, {
              params: _.merge(this.props.params, params),
              location: _.merge(this.props.location, { query: query }),
              currentUser: fixtures.user,
            }),
          )
        )
      },

      render() {
        return this.renderChildren()
      },
    })

    ReactDOM.render(
      
        
          
        
      ,
      container,
      function() {
        cb(TestUtils.findRenderedComponentWithType(this, routeHandler))
      },
    )
  },
github nfl / react-metrics / test / ReactMetrics / willTrackPageView.spec.js View on Github external
JSON.stringify(state)
                );
                expect(JSON.stringify(routeState.params)).to.equal(
                    JSON.stringify({id: "123"})
                );
                done();
                return true;
            }

            render() {
                return <div><h2>Page</h2>{this.props.children}</div>;
            }
        }

        ReactDOM.render(
            
                
                    
                
            ,
            node,
            function() {
                this.history.pushState(state, "/page/123?param1=value1");
            }
        );
    });
});
github mykhailo-riabokon / redux-form-universal-example / src / server / middleware / routing.js View on Github external
/**
 * Created by mikhail on 16.07.15.
 */
import React from 'react';
import Router from 'react-router';
import Promise from 'promise';
import routes from '../../client/routing/routes.js';
import renderFullPage from '../../utils/renderFullPage.js';
import router from '../../client/routing/router.js';
import createLocation from 'history/lib/createLocation';
import createMemoryHistory from 'history/lib/createMemoryHistory';

const history = createMemoryHistory();

export default function routing(req, res) {
  let location = createLocation(req.path);

  router(location, history, req, res)
    .then((reactEl) => {
      try {
        let reactStr = React.renderToString(reactEl);
        res.send(renderFullPage(reactStr));
      } catch (err) {
        res.status(500).send({error: err.toString()});
      }
    }, ({message, code}) => {
      console.error(message, code);
      res.sendStatus(code || 500);
    });
github pierreavizou / universal-routed-flux-demo / routes / routes.js View on Github external
import React from 'react';
import { Router, Route} from 'react-router/umd/ReactRouter';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import createMemoryHistory from 'history/lib/createMemoryHistory';

var history;
if (typeof(window) !== 'undefined'){
    history = createBrowserHistory();
}
else {
    history = createMemoryHistory(); //This kind of history is needed for server-side rendering.
}

import TodoApp from '../components/TodoApp.react';
import LogDiv from '../components/Logs.react';
import AppContainer from '../components/AppContainer.react';

var routes = (
    
        
            
                
            
        
    
);
github cmux / koot / packages / koot / ReactApp / server / ssr.js View on Github external
    const memoryHistory = useRouterHistory(() => createMemoryHistory(url))(
        historyConfig