How to use the history/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 Sitecore / jss / samples / advanced-sample-react / src / server.js View on Github external
state.app = {
      ...state.app,
      ...parsedData.sitecore,
    };
  }

  // init i18n
  const routeParams = resolveCurrentRoute(path, parsedViewBag);
  i18nInit(routeParams.currentLang, false /* isClient */, parsedViewBag.dictionary);
  state.app = {
    ...state.app,
    ...routeParams,
  };

  const store = initStore(state);
  const history = createMemoryHistory({
    initialEntries: [path],
  });
  const context = {};
  const component = (
    
      
        
      
    
  );
  const html = ReactDOM.renderToString(
    
  );

  if (context.url) {
    result.redirect = context.url;
github TheBrainFamily / TheBrain2.0 / newMobileClient / store.js View on Github external
import { applyMiddleware, combineReducers, compose, createStore } from 'redux'
import { routerMiddleware, routerReducer } from 'react-router-redux'
import createHistory from 'history/createMemoryHistory'
import { ApolloClient } from 'apollo-client'
import reducers from './reducers'
import devTools from 'remote-redux-devtools'
import { networkInterface } from './networkInterface'

const client = new ApolloClient({
  networkInterface
})

// TODO this file needs a clean up! we create the store and client and in tests we create different ones - this should be streamlined similarly to what we do in web client
const history = createHistory()

const returnStore = (client, history = createHistory()) => {
  return createStore(
    combineReducers({
      ...reducers,
      router: routerReducer,
      apollo: client.reducer()
    }),
    {}, // initial state
    compose(
      applyMiddleware(routerMiddleware(history), client.middleware()),
      devTools()
    )
  )
}
github TobiasWalle / rush / src / app / server / ui-server.tsx View on Github external
function createReduxStore() {
  // Setup state
  const initialState = {};
  const history = createMemoryHistory();
  return createStore(
    require('../modules/root').reducer,
    initialState,
    getStoreMiddleware(history)
  );
}
github infernojs / inferno / packages / inferno-router / __tests__ / Route.spec.jsx View on Github external
describe('', () => {
  const history = createMemoryHistory();
  const node = document.createElement('div');

  it('renders a function', () => {
    const TEXT = 'Mrs. Kato';
    const node = document.createElement('div');
    render(
      
         <div>{TEXT}</div>} /&gt;
      ,
      node
    );

    expect(node.innerHTML).toContain(TEXT);
  });

  it('renders a child element', () =&gt; {
github nusmodifications / nusmods / v3 / src / js / test-utils / createHistory.js View on Github external
export default function createHistory(
  initialEntries: string | string[] = '/',
  matchParams: MatchShape = {},
): ContextRouter {
  const entries = _.castArray(initialEntries);
  const history = createMemoryHistory({ initialEntries: entries });
  const { params = {}, isExact = true } = matchParams;

  const match = {
    params,
    isExact,
    path: entries[0],
    url: entries[0],
  };

  return {
    history,
    match,
    location: history.location,
  };
}
github raineroviir / react-redux-socketio-chat / src / server / server.prod.js View on Github external
app.get('/*', function(req, res) {
  const history = createHistory()
  const location = history.location

  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 FormidableLabs / redux-little-router / src / environment / express-router.js View on Github external
export const createExpressRouter = (installer: Function) => ({
  routes,
  request,
  historyOptions = {}
}: ServerRouterArgs) => {
  const history = createMemoryHistory(historyOptions);
  const location = locationForRequest(request);

  return installer({ routes, history, location });
};
github frontarm / navi / site / wrappers / ExampleWrapper.js View on Github external
handleChangePage(prev, next) {
    if (prev.page != next.page) {
      this.history = createMemoryHistory({
        initialEntries: [ next.page.initialPath || '/' ],
        getUserConfirmation: (message, callback) => {
          callback(window.confirm(message))
        }
      })
    }
  }
github samlogan / universal-firebase-react / server / render / middleware.js View on Github external
export default function render(req, res) {
  const history = createMemoryHistory();
  const store = configureStore({}, history);
  if (!req.url || req.url.includes('assets')) return null;
  const matchedRoutes = matchRoutes(routes, req.url);
  store.dispatch({ type: types.CREATE_REQUEST });
  return fetchDataForRoute(matchedRoutes)
    .then((data) =&gt; {
      store.dispatch({ type: types.REQUEST_SUCCESS, data });
      const initialState = store.getState();
      const context = {};
      const componentHTML = renderToString(
        
          
            {renderRoutes(routes)}
          
        ,
      );
github wooline / react-coat / build / es5 / Application.js View on Github external
export function renderApp(moduleGetter, appName, initialEntries, storeOptions, ssrInitStoreKey, renderToStream) {
    if (storeOptions === void 0) { storeOptions = {}; }
    if (ssrInitStoreKey === void 0) { ssrInitStoreKey = "reactCoatInitStore"; }
    if (renderToStream === void 0) { renderToStream = false; }
    MetaData.appModuleName = appName;
    var history = createMemoryHistory({ initialEntries: initialEntries });
    var store = buildStore(history, storeOptions.reducers, storeOptions.middlewares, storeOptions.enhancers, storeOptions.initData, storeOptions.routerParser);
    var appModule = moduleGetter[appName]();
    var render = renderToStream ? renderToNodeStream : renderToString;
    return appModule
        .model(store)
        .catch(function (err) {
        return store.dispatch(errorAction(err));
    })
        .then(function () {
        var data = store.getState();
        return {
            ssrInitStoreKey: ssrInitStoreKey,
            data: data,
            html: render(React.createElement(Provider, { store: store },
                React.createElement(ConnectedRouter, { history: history },
                    React.createElement(appModule.views.Main, null)))),