Reactjs 使用webpack开发服务器重新加载时嵌套的react路由器URL中断
在同一个话题上有很多问题被问到,比如和,但我无法解决我的问题 react应用程序在不重新加载的情况下运行良好,但在嵌套react路由器URL上重新加载或手动刷新时,它会中断 以下是我的路线:Reactjs 使用webpack开发服务器重新加载时嵌套的react路由器URL中断,reactjs,webpack,react-router,webpack-dev-server,Reactjs,Webpack,React Router,Webpack Dev Server,在同一个话题上有很多问题被问到,比如和,但我无法解决我的问题 react应用程序在不重新加载的情况下运行良好,但在嵌套react路由器URL上重新加载或手动刷新时,它会中断 以下是我的路线: ReactDOM.render( <Provider store={store}> <Router history={history}> <Route path='/' component={App}> <IndexRoute
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route path='/' component={App}>
<IndexRoute component={GoogleLoginComponent} />
<Route path='home' component={HomeComponent} onEnter={authRequired.bind(this, store)}>
</Route>
<Route path='register' component={RegisterComponent} onEnter={authRequired.bind(this, store)}>
</Route>
<Route path='eventCreated/eventId=:eventId' component={EventShareComponent}>
</Route>
<Route path='event/eventId=:eventId' component={EventPageComponent}>
</Route>
</Route>
</Router>
</Provider>,
document.getElementById('app')
);
我已经重写了嵌套URL以重定向到index.html,但仍然无法找出错误所在。我也试过让历史回退成为真实的我认为你应该使用历史={browserHistory}使用historyApiFallback,您还应该访问
http://localhost:3000/eventCreated?eventId=1234
而不是http://localhost:3000/eventCreated/eventId=1234
因为eventId是一个查询参数。你的是无效的url@ShubhamKhatri谢谢你提供的额外信息,我会改变的。关于BrowserHistory,我在Router的历史道具中添加了BrowserHistory。这是代码const history=syncHistoryWithStore(browserHistory,store);我已经在路由器的历史属性中添加了历史常数。您还需要将路由路径
更改为
。让我知道它是否对你有效,我一定会给你回信的change@ShubhamKhatri我尝试更改为eventCreated/:eventId,但出现了相同的错误。您想让我为eventId创建子路由吗?我认为您应该使用history={browserHistory}和historyApiFallback,并且您应该访问http://localhost:3000/eventCreated?eventId=1234
而不是http://localhost:3000/eventCreated/eventId=1234
因为eventId是一个查询参数。你的是无效的url@ShubhamKhatri谢谢你提供的额外信息,我会改变的。关于BrowserHistory,我在Router的历史道具中添加了BrowserHistory。这是代码const history=syncHistoryWithStore(browserHistory,store);我已经在路由器的历史属性中添加了历史常数。您还需要将路由路径
更改为
。让我知道它是否对你有效,我一定会给你回信的change@ShubhamKhatri我尝试更改为eventCreated/:eventId,但出现了相同的错误。是否要我为eventId创建子路由?
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: {
index: 'index.html',
rewrites: [
{ from: /\/event/, to: 'index.html'}
]
}
}).listen(PORT, function(err, result) {
if (err) console.log(err);
console.log('Listening at port '+ PORT);
});