0

I'm facing this error while trying to integrate react-router-redux into my React project. Following is my app.js code and reducers/index.js

//app.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import createHistory from 'history/createBrowserHistory';
import { Route } from 'react-router';

import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux';

import App from './components/app.js';
import reducers from './reducers';

const history = createHistory();
const middleware = routerMiddleware(history);

// Add the reducer to your store on the `router` key
// Also apply our middleware for navigating
const store = createStore({
    ...reducers,
    router: routerReducer
  },
  applyMiddleware(middleware)
);

const About = () => {
  return (<div>
    Will this work?
  </div>);
}

ReactDOM.render(
  <Provider store={store}>
    <ConnectedRouter history={history}>
      <div>
        <Route exact path="/" component={App}/>
        <Route path="/about" component={About}/>
      </div>
    </ConnectedRouter>
  </Provider>
  , document.querySelector('#app'));

Here is my reducers/index.js code.

//reducers/index.js
import { combineReducers } from 'redux';
import { mobileLinks } from './reducer_header';
import UserDetailsReducer from './reducer_user_details';

const rootReducer = combineReducers({
  mobileLinks,
  userDetails: UserDetailsReducer
});

export default rootReducer;

What do I do to fix this? I'm unable to find any examples for the new version of react-router-redux. I've tried moving the routerReducer to reducers/index.js but that didn't work either. Can someone please help?

1 Answer 1

3

Most likely you do not have Babel set to transpile the Object Spread Operator, you can read up on it here.

You can simply install the Babel "Object rest spread transform" preset like so: npm install --save-dev babel-plugin-transform-object-rest-spread

And add it to your list of plugins:

{
    "plugins": [
        // Other plugins...
        "transform-object-rest-spread"
    ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I did not know the solution was this simple!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.