Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning about router in console #4

Closed
jonaskello opened this issue Jan 1, 2016 · 5 comments
Closed

Warning about router in console #4

jonaskello opened this issue Jan 1, 2016 · 5 comments

Comments

@jonaskello
Copy link

When I run this as-is in Chrome I get this in the console:

Warning: You cannot change <Router routes>; it will be ignored

It seems to work anyway but would be nice to get rid of the warning.

@jonaskello jonaskello changed the title Warning in console Warning about router in console Jan 1, 2016
@capaj
Copy link
Owner

capaj commented Jan 2, 2016

yeah, this is something I started to get as well. Will definitely investigate when I have time.

@fryck
Copy link

fryck commented Jan 29, 2016

+1 ...

@grady-lad
Copy link

I was coming across this today too, it seemed to not like forceUpdate() within the RenderForcer class.
I can still hot-reload by removing forceUpdate() but I still need this
class to perform hot reloads which has confused me more.


class RenderForcer extends Component {

  constructor() {
    super();
  }

  componentWillMount() {
    // this.forceUpdate();
  }

  render() {
    return (
      <Provider store={store}>
        <div>
        <Router history={createBrowserHistory()}>
          {getRoutes()}
        </Router>
        <DevTools/>
        </div>
      </Provider>
    );
  }
}

if (__DEVTOOLS__) {
  ReactDOM.render(
    <RenderForcer/>,
    document.getElementById('app')
  );
}

@dmi3y
Copy link

dmi3y commented May 24, 2016

Based on this comment.

I did modify the app.js like so (moved Route from render Router into top level constant):

    import React from 'react'
    import ReactDOM from 'react-dom'
    import { browserHistory } from 'react-router'
    import { Router, Route } from 'react-router'

    import Home from './routes/home'
    import { IntlProvider, addLocaleData } from 'react-intl'
    import en from 'react-intl/locale-data/en'
    addLocaleData(en)

    const routes = <Route path='/' component={Home}/>

    class RenderForcer extends React.Component {
      constructor () {
        super()
      }
      componentWillMount () {
        this.forceUpdate()  // a little hack to help us rerender when this module is reloaded
      }
      render () {

        return <IntlProvider locale='en'>
          <Router history={browserHistory}>
            {routes}
          </Router>
        </IntlProvider>
      }
    }

    ReactDOM.render((
      <RenderForcer/>
    ), document.getElementById('app'))

Which made error (warning) goes away.

Also it seems makes sense to separate routes. Either way, if this is something that considered as improvement I can open MR.

@capaj capaj closed this as completed in 40bc1d2 May 24, 2016
@capaj
Copy link
Owner

capaj commented May 24, 2016

@dmi3y I did it already, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants