简体   繁体   English

在生产模式下刷新页面时,React组件未呈现

[英]React component is not rendering when the pages got refreshed on production mode

React js component is not rendering when the pages got refreshed and inner pages on production mode But its Working in Development Mode with same Code.. 在页面刷新和内部页面在生产模式下时,React js组件未呈现,但在开发模式下使用相同的代码工作。

I'm Using React Router V4, React js with Redux, Webpack. 我正在使用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>
          );
        }
      }

Check Screenshot 检查截图

I guess you need to setup the publicPath option in your webpack output section. 我猜您需要在webpack output部分中设置publicPath选项。

output: {
  ...
  publicPath: '/'
}

The error you are having is because when you use a route like /posts/203075 and your publicPath is not configured then the resources can't be founded. 您遇到的错误是因为当您使用/posts/203075 publicPath类的路由并且未配置publicPath ,无法建立资源。 Webpack thinks that your files are in this kind of route /posts/styles.css . Webpack认为您的文件位于/posts/styles.css这样的路由中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM