electron-react-boilerplate: Store and History undefined in Root.js, even when explicitly passed in.

Line 96 of Router.js:

this.transitionManager = this.createTransitionManager();

all my inputs are defined at runtime I’ve confirmed, and this.createTransitionManager() is also defined.

After passing that line though, this.transitionManager is not defined, and the packaged application fails with:

Uncaught (in promise) TypeError: Cannot read property 'getCurrentLocation' of undefined(…) on line 99 of Router.js

Any ideas on why this might be the case?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

Okay so fixing this issue, here’s the code and how it works:

index.js

import _ from 'lodash';
import React from 'react';
import { Provider } from 'react-redux';
import { render } from 'react-dom';
import { syncHistoryWithStore } from 'react-router-redux';
import { Router, hashHistory } from 'react-router';
import { AppContainer } from 'react-hot-loader';

import configureStore from './store/configureStore';
import myRoutes from './routes';
import Root from './containers/Root';

function ProductionRoot() {
  return (
    <Provider store={store}>
      <Router key={Math.random()} history={history} routes={myRoutes} />
    </Provider>
  );
}

function createStoreFunction() {
	store = configureStore();
	history = syncHistoryWithStore(hashHistory, store);
	render(
	  <AppContainer>
	    {(process.env.NODE_ENV != 'development') ? <ProductionRoot store={store} history={history} />  :  <Root store={store} history={history} /> }
	  </AppContainer>,
	  document.getElementById('root')
	);

	if (module.hot) {
	  module.hot.accept('./containers/Root', () => {
	    const NextRoot = require('./containers/Root'); // eslint-disable-line global-require
	    render(
	      <AppContainer>
	        <NextRoot store={store} history={history} />
	      </AppContainer>,
	      document.getElementById('root')
	    );
	  });
	}

In my particular case, in production, store and history are undefined, unless root is within the same file, and the store and history are not explicitly passed in. This is a workaround for that issue if anyone else runs into it.

@amilajack it amazes me you are not even out of school.

I managed to resolve the issue, though I didn’t exactly manage to figure out what the issue was. It was something in my store I think? I’m really not sure unfortunately. Thanks very much for your help.

What is the full stacktrace?