Javascript React路由器不工作,即使设置了historyApiFallback

Javascript React路由器不工作,即使设置了historyApiFallback,javascript,reactjs,webpack,react-router,Javascript,Reactjs,Webpack,React Router,我有以下问题:React路由器无法工作。无论我重新加载页面还是链接到路由,它都不起作用。在重新加载时,我会看到一个白色页面和一个链接,除了URL更改之外,什么都不会发生。奇怪的是,当我更改定义路由的源文件(App.js)时,我可以让它显示正确的组件。我正在使用WebpackDevServer,所以我认为问题存在,但我已经尝试了所有在线找到的解决方案,但没有任何效果。救命 devserver.js: var webpack = require('webpack'); var WebpackDevS

我有以下问题:React路由器无法工作。无论我重新加载页面还是链接到路由,它都不起作用。在重新加载时,我会看到一个白色页面和一个链接,除了URL更改之外,什么都不会发生。奇怪的是,当我更改定义路由的源文件(App.js)时,我可以让它显示正确的组件。我正在使用WebpackDevServer,所以我认为问题存在,但我已经尝试了所有在线找到的解决方案,但没有任何效果。救命

devserver.js:

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

var server = new WebpackDevServer(webpack(config), {
  publicPath: config.output.publicPath,
  hot: true,
  historyApiFallback: true
})

server.listen(3000, 'localhost', function (err, result) {
  if (err) {
    return console.log(err);
  }

  console.log('Listening at http://localhost:3000/');
});
App.js:

@observer
export default class App extends Component {

constructor(props) {
    super(props)
    this.stores = this.props.stores
    this.history = this.props.history
}

componentDidMount() {
    this.authenticate()
}

authenticate(e) {
    if (e) e.preventDefault()
    this.props.stores.appState.authenticate()
}

render() {
    return (
        <MuiThemeProvider>
            <Router history={this.history}>
                <Provider {...this.stores}>
                    <div className="wrapper">
                        {/*<DevTools />*/}

                        <TopBar />

                        <Route
                            exact
                            path="/"
                            render={(props) => <LazyRoute {...props} component={import('./Home')}/>}
                        />

                        <Route
                            path="library"
                            render={(props) => <LazyRoute {...props} component={import('./Library')}/>}
                        />

                    </div>
                </Provider>
            </Router>
        </MuiThemeProvider>
    )
}
}
@observer
导出默认类应用程序扩展组件{
建造师(道具){
超级(道具)
this.stores=this.props.stores
this.history=this.props.history
}
componentDidMount(){
这是authenticate()
}
认证(e){
如果(e)e.防止违约()
this.props.stores.appState.authenticate()
}
render(){
返回(
{/**/}
}
/>
}
/>
)
}
}