[英]React component is not rendering when the pages got refreshed on production mode
在页面刷新和内部页面在生产模式下时,React js组件未呈现,但在开发模式下使用相同的代码工作。
我正在使用React Router V4,带有Redux的React js,Webpack。
class Router extends React.Component {
render() {
return (
<Provider store={store}>
<BrowserRouter>
<Switch>
<Route exact path="/" component={LandingPage} />
<Route exact path="/chapterlist" component={chapterList} />
<Route exact path="/posts/:id" component={ChapterDetail} />
<Route path="*" component={NotFound} />
</Switch>
</BrowserRouter>
</Provider>
);
}
}
我猜您需要在webpack output
部分中设置publicPath
选项。
output: {
...
publicPath: '/'
}
您遇到的错误是因为当您使用/posts/203075
publicPath
类的路由并且未配置publicPath
,无法建立资源。 Webpack认为您的文件位于/posts/styles.css
这样的路由中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.