it's my first project that use react
,react-router
,react-hot-loader
,webpack-dev-server
and webpack
. when I change the code in react component, the hot-loader become effective, but at the same time, the console tell me a warning:
You cannot change 《Router routes》; it will be ignored.
I don't know how to solve this issue.there is code:
webpack code:
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'source-map' ,
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./jsx/index'
],
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js', '.jsx', 'json']
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['react-hot', 'babel'],
}]
},
watch:true
};
index code:
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, Link } from 'react-router'
import App from './index/app'
import About from './index/about'
import Inbox from './index/inbox'
class Routers extends React.Component {
render() {
return (
<Router>
<Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox} />
</Route>
</Router>
);
}
}
ReactDOM.render(<Routers />, document.getElementById('root'));
thank you !!!!
The router actually should never change, so you should be able to just return false for shouldComponentUpdate() in this case.
I know this is an old question, but someone might find this useful. I tried a lot of stuff and what finally worked for me is:
My Solution is change "Reflux.Component" to "React.Component"
i have the same issue,my Solution is change "import { Router, Route, Link } from 'react-router'" to "import {HashRouter, Route, Link} from 'react-router-dom'" my code:
Only thing you need to do, it's to throw
<Route />
out of render() method.So, there are many ways to solve this issue.
Most Official way is what @Stormy say.
My solution like this:
Stormy's suggestion of using
<Router routes={Routes}/>
worked for me. Here are my warning free code snippits with react hot module replacement:./index.js
./components/Routes.jsx