使用React.Lazy进行代码拆分无法正常工作

时间:2020-04-29 20:26:23

标签: javascript reactjs react-router react-hooks

我正在尝试拆分我的捆绑包,以便仅加载出于更好性能目的所需的捆绑包,而我尝试了以下操作:

const Registration = lazy(() => import('./modules/Registration/Components/Registration'))
function App() {
  const { state } = useContext(GlobalStore)
  return (
    <ApolloProvider client={apolloClient}>
      <Router>
        <Wrapper>
          <Header />
          <Page>
            <Suspense fallback={<div>Loading component...</div>}>
              <Switch>
                <Route path="/" exact>
                  <Registration />
                </Route>
                <Route>
                  <PageNotFound />
                </Route>
                <Route path="/not-authorized" exact></Route>
              </Switch>
            </Suspense>
          </Page>
          <Footer />
        </Wrapper>
      </Router>
    </ApolloProvider>
  )
}

由于某种原因,这无法正常显示错误:

TypeError:无法获取动态导入的模块:http://localhost:3000/static/js/modules/Registration/Components/Registration

0 个答案:

没有答案