Skip to content
This repository was archived by the owner on May 7, 2022. It is now read-only.

1.2.0

Choose a tag to compare

@hyy1115 hyy1115 released this 17 Jun 11:08
· 167 commits to master since this release

使用webpack的import()实现代码切割,不只是在路由中使用,你可以在任意组件内部使用代码切割方法懒加载组件,。

在路由route中,你可以这样

//封装好的异步方法,非原创,使用了一个大神写的函数。
import { asyncComponent } from './AsyncComponent'

//使用asyncComponent(),你就能将Promise的返回值赋给一个变量
const Search = asyncComponent(() => import(/* webpackChunkName: "search" */ "./containers/Search/searchContainer"))

<Route path="/xx" component={Search} />

请注意import()方法是异步的,你不能这样使用

const Foo = import("./xx") // 错误的写法

<Route path="/xx" component={import("./xxx")} /> //错误的写法