1
import React, { Component,lazy,Suspense} from 'react';
import LayoutComponent from './components/layout/Layout'
import BurgerBuilderContainer from './Containers/BurgerBuilder/BurgerBuilder'
import CheckoutContainer from './Containers/CheckOut/Checkout'
import { Route, Switch,withRouter } from 'react-router-dom'
 const OrdersContainer = lazy(()=> {
  return import('./Containers/Orders/Orders')
 })

面对错误

render(){
return (
  <div>
    <Suspense fallback={<div>Loading...</div>}>
    <LayoutComponent>
      <Switch>
      <Route path="/Logout" component={LogoutContainer}></Route>
      <Route path="/Auth" component={AuthContainer}></Route>
        <Route path="/Orders" component={OrdersContainer}></Route>
        <Route path="/checkout" component={CheckoutContainer}></Route>
        <Route path="/" component={BurgerBuilderContainer}></Route>
      </Switch>
    </LayoutComponent>
    </Suspense>
  </div>
);
}

AsPer 错误延迟加载在导入时显示错误,在使用延迟加载应用程序工作正常之前。

4

1 回答 1

1

你能试试吗

const OrdersContainer= React.lazy(() => import('./Containers/Orders/Orders'));

如果错误继续尝试

const OrdersContainer= React.lazy(() => require('./Containers/Orders/Orders'));

如果仍然继续

React.lazy(() => import("./Containers/Orders/Orders").then(x => x.default))

最后

进口@babel/plugin-syntax-dynamic-import

于 2020-04-23T18:04:44.197 回答