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 ...
随机推荐
- 使用 async/ await 进行 异步 编程
一.异步函数 异步函数概念. 通常 是 指用 async 修饰 符 声明 的, 可 包含 await 表达式 的 方法 或 匿名 函数 1. 从 语言 的 视角 来看, 这些 await 表达式 正是 ...
- Linux常见后缀缩写含义
ctl: control rc: run control (A run-control file is a file of declarations or commands associated wi ...
- Linux下安装桌面
1. 安装之前先测试是否有桌面 2. 建立yum源文件 3. 挂载好光盘(/rhel自己创建) 4. 使用yum list 查看 ...
- js数组去重的四种方式
// 删除重复的 function only(arr){ for(var i=0;i<arr.length;i++){ for(var j = i+1;j<arr.length;j++){ ...
- HDU 1052 Tian Ji -- The Horse Racing【贪心在动态规划中的运用】
算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输 ...
- linux进程的有效用户ID
进程的有效用户ID用于文件访问时的权限检查.通常,有效用户ID等于实际用户ID(也就是你登录是的用户ID),有效组ID等于实际组ID. 我们知道每个文件针对不同的user有不同的读.写.执行权限.当执 ...
- eclipse 启动程序时错误弹窗:multiple problems have occurred
.log内容如下: !ENTRY org.eclipse.ui 4 4 2017-04-14 09:31:05.341!MESSAGE An internal error has occurred.! ...
- luoguP4512 【模板】多项式除法 NTT+多项式求逆+多项式除法
Code: #include<bits/stdc++.h> #define maxn 300000 #define ll long long #define MOD 998244353 # ...
- P3376 【模板】网络最大流(luogu)
P3376 [模板]网络最大流(luogu) 最大流的dinic算法模板(采取了多种优化) 优化 时间 inline+当前弧+炸点+多路增广 174ms no 当前弧 175ms no 炸点 249 ...
- HDU 1575 Tr A( 简单矩阵快速幂 )
链接:传送门 思路:简单矩阵快速幂,算完 A^k 后再求一遍主对角线上的和取个模 /********************************************************** ...