【问题标题】:React component is not rendering when the pages got refreshed on production mode在生产模式下刷新页面时,React 组件未呈现
【发布时间】:2018-02-22 05:01:09
【问题描述】:

当页面刷新时,React js 组件不渲染,内页处于生产模式,但它在开发模式下工作,代码相同..

我正在使用 React Router V4、React js 和 Redux、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

【问题讨论】:

  • 尝试使用 如果路由有子路由,则不能使用“精确”路径。

标签: javascript reactjs redux react-router react-redux


【解决方案1】:

我猜你需要在 webpack 的 output 部分设置 publicPath 选项。

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

您遇到的错误是因为当您使用/posts/203075 之类的路由并且您的publicPath 未配置时,则无法创建资源。 Webpack 认为你的文件在这种路由/posts/styles.css

【讨论】:

  • 请分享你的 webpack 配置。
猜你喜欢
  • 2018-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 2023-01-26
  • 1970-01-01
  • 2021-10-21
  • 2022-10-24
相关资源
最近更新 更多