Redux: React router error - [react-router] You cannot change <Router routes>; it will be ignored

Created on 7 Apr 2016  路  1Comment  路  Source: reduxjs/redux

I'm using reactjs, react-router & redux in my application. I'm using async actions, following is my action.js code

signUser(state,user) {
    return function (dispatch){
      return dispatch(requestSignUp());
    }
  }

export default function requestSignUp(){
 return {
   type: Actions.REQUEST,
   signUserReducer:{
    action: Actions.REQUEST
   }
  }
 }

Following is my store.js code

const reducer = combineReducers(reducers);
 let finalState = compose(applyMiddleware(thunk, logger()))(createStore)

 export default function configureStore(initialState) {
   return finalState(reducer, initialState);
  }

Following is my reducer.js code

export default function signUserReducer(state = initialState, action) {
 if (typeof state == 'undefined') {
    return state;
  }
 switch (action.type) {
    case Actions.REQUEST:
        return Object.assign({}, state, {
            action: action.signUserReducer.action
        });
    default:
        return state;
    }
    }

and then I used conect method to connect my app with store, Now whenever I'm dispatching an action an error displays on my browser console stating

Warning: [react-router] You cannot change 'Router routes'; it will be ignored

I tried solving this with 'react-router-redux', but it's not solving.

Most helpful comment

A good first step would be to look again into the error message. It鈥檚 not a random error; it actually tells what happened. It says that Router component cannot accept new value of routes prop. This means you are recreating new routes every time you render the root component, rather than create them once for the lifetime of your app, which is the scenario React Router intends to support. The conclusion is you would need to look into where you render the Router component, and make sure you don't create routes on every render. I would always suggest to consider the error message before trying to install additional dependencies in hope they would solve the problem, as they usually introduce more problems 馃檪

We do have an example using React Router in this repo (real-world) so I don't think there is anything actionable for us here. In the future please try to use a support forum rather than Redux issue tracker for usage questions. Thank you!

>All comments

A good first step would be to look again into the error message. It鈥檚 not a random error; it actually tells what happened. It says that Router component cannot accept new value of routes prop. This means you are recreating new routes every time you render the root component, rather than create them once for the lifetime of your app, which is the scenario React Router intends to support. The conclusion is you would need to look into where you render the Router component, and make sure you don't create routes on every render. I would always suggest to consider the error message before trying to install additional dependencies in hope they would solve the problem, as they usually introduce more problems 馃檪

We do have an example using React Router in this repo (real-world) so I don't think there is anything actionable for us here. In the future please try to use a support forum rather than Redux issue tracker for usage questions. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olalonde picture olalonde  路  3Comments

parallelthought picture parallelthought  路  3Comments

dmitry-zaets picture dmitry-zaets  路  3Comments

benoneal picture benoneal  路  3Comments

cloudfroster picture cloudfroster  路  3Comments