react-route4 按需加载配置心得
const routes = {
path: '/',
component: AppCom,
indexRoute: {
component: Admin
},
childRoutes: [
{
path: 'edit/:id',
getComponent: (nextState, cb) => {
require.ensure([], (require) => {
cb(null, require('../entry/admin/edit.jsx'))
})
}
}
]
}
<Router routes={routes} history={hashHistory} />
import React from 'react'; export default class Bundle extends React.Component {
constructor(props) {
super(props);
this.state = {
mod: null
};
} componentWillMount() {
this.load(this.props)
} componentWillReceiveProps(nextProps) {
if (nextProps.load !== this.props.load) {
this.load(nextProps)
}
} load(props) {
this.setState({
mod: null
});
props.load().then((mod) => {
this.setState({
mod: mod.default ? mod.default : mod
});
});
} render() {
return this.state.mod ? this.props.children(this.state.mod) : null;
}
}
import Bundle from './Bundle';
const routeObj = {
url1:'url1/url1',
url2:'url2/url2',
url3:'url3/url3',
}
let components = {};
for(let route in routeObj){
components[route] = (props) => (
<Bundle load={() => import(`../entry/${routeObj[route]}`)}>
{(Component) => <Component {...props}/>}
</Bundle>
);
}
import(`../entry/${routeObj[route]}`)}
<Route exact path="/" component={components.url1}/>
output: {
path: paths.appBuild,
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js'
}
react-route4 按需加载配置心得的更多相关文章
- react antd样式按需加载配置以及与css modules模块化的冲突问题
通过create-react-app脚手架生成一个项目 然后运行npm run eject 把webpack的一些配置从react-scripts模块弹射出来, 方便自己手工增减,暴露出来的配置文件在 ...
- React Router 按需加载+服务器渲染的闪屏问题
伴随着React协议的『妥协』(v16采用MIT),React为项目的主体,这个在短期内是不会改变的了,在平时使用过程中发现了如下这个问题: 在服务器渲染的时候,刷新页面会出现闪屏的现象(白屏一闪而过 ...
- antd按需加载,配置babel-plugin-import插件,编译后报错.bezierEasingMixin()解决方案
报错如下: ./node_modules/antd/lib/button/style/index.less (./node_modules/css-loader??ref--6-oneOf-7-1!. ...
- react路由按需加载方法
使用router4之后以前的按需加载方法require.ensure 是不好使了. 所以我们改用react-loadable插件做按需加载. 第一步: yarn add react-loadable ...
- mybatis 启用延迟加载和按需加载配置
启用延迟加载和按需加载 Mybatis配置文件中通过两个属性lazyLoadingEnabled和aggressiveLazyLoading来控制延迟加载和按需加载. lazyLoadingEnabl ...
- Vuetify按需加载配置
自己配置vuetify按需加载的步骤,在此记录: 执行npm install vuetify –save 或 yarn add vuetify添加vuetify添加依赖执行npm install -- ...
- react CRA antd 按需加载配置 lessloader
webpack配置 webpack.config.dev.js, webpack.config.prod同理. 'use strict'; const autoprefixer = require(' ...
- 配置react / antd 按需加载 并且使用less(react v16)
1.开启项目 并且执行 yarn eject 下载好我们需要的插件(babel-plugin-import less less-loader antd react-loadable ...
- nuxt中iview按需加载配置
在plugins/iview.js中修改 初始代码如下 import Vue from 'vue' import iView from 'iview' import locale from 'ivie ...
随机推荐
- 【POJ 1733】 Parity Game
[题目链接] http://poj.org/problem?id=1 [算法] 并查集 [代码] #include <algorithm> #include <bitset> ...
- ubuntu sublime text 2 破解版
原网地址 : http://blog.csdn.net/icephone/article/details/8217567 关于sublime text 2 的一个使用教程以及前端的不错的学习博客 ht ...
- POJ 3180 Tarjan
题意:找强连通中点数大于2的强连通分量个数 思路:Tarjan // By SiriusRen #include <cstdio> #include <algorithm> u ...
- null和undifned的区别
null和undifned的区别 1 从类型方面:null的类型是对象,undified的类型是undified. 2 从定义方面:null是一个表示"无"的对象,转为数值时为0: ...
- 常用几个空格的 Unicode 码
const SPACE_UNICODE = { 'ensp': '\u2002', 'emsp': '\u2003', 'nbsp': '\u00a0' }
- HDU 1203 I NEED A OFFER!【01背包】
解题思路:攒下的钱n相当于包的容量,然后是m个学校的申请费用,申请费用相当于每一个物品的消耗,得到offer的概率相当于每一个物品的价值. 因为要求的是至少得到一份0ffer的概率的最大概率,可以转化 ...
- Java上传且后台解析XML文件
后台代码: import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStream ...
- failed to push some refs to 'git@github.com:RocsSun/mytest.git
Git推送到GitHub仓库失败 使用Git将文件推送至GitHub的远程仓库时,报错failed to push some refs to 'git@github.com:RocsSun/mytes ...
- Python笔记27----时间解析
1.将时间字符串解析成真正的时间 time.strptime http://www.runoob.com/python/att-time-strptime.html 代码: import time s ...
- Lua 中的 RSA 加解密实现
记得之前,部门某款游戏陆陆续续收到一些玩家反馈,抱怨在登录游戏时会等待很久.初步排查后基本断定可能是此游戏的登录服务器程序某块代码有问题,于是即安排了服务器同事作排查分析但一直无果. 之后我时间有了空 ...