我使用yeoman用react和webpack设置我的项目 . 然后,我手动将react-router添加到项目中 . 热重载工作正常,直到我有路径 .

所以在我的index.js中,我有

<Provider store={store}>
<Router history={browserHistory}>
  <Route path="/" component={App}>
    <IndexRoute component={Dashboard}/>
    <Route path="/app" component={Nav}>
      <Route path="/app/payable/export" component={Export}/>
    </Route>
  </Route>
  <Route path="*" component={NotFound}/>
</Router>

热重载适用于组件:App和Dashboard,因为路径只是“/” .

但热重载不适用于Export . 我收到了这个错误:

http://localhost:9300/app/payable/assets/31f035eb918b53b2078f.hot-update.json 404 (Not Found)

它似乎是在资源路径中附加路径路径,但webpack只在“/ assets /”下生成热重载文件 . 但是,如果我在react-router中使用hashHistory,我没有问题 . 只有当我使用broswerHistory时 .

这是我的webpack配置:

const path = require('path');
const srcPath = path.join(__dirname, '/../src');
...
{
publicPath: '/assets/',
srcPath: srcPath
}