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 ...
 
随机推荐
- NEU 1040 Count
			
1040: Count 时间限制: 1 Sec 内存限制: 128 MB提交: 59 解决: 23[提交][状态][讨论版] 题目描述 Many ACM team name may be very ...
 - js接收文件流并下载
			
js接收文件流并下载 标签(空格分隔): js 在此输入正文 <script type="text/javascript"> function download(fil ...
 - redis的主从模式
			
主从通信过程 Master配置: 1:关闭rdb快照(备份工作交给slave) 2:可以开启aof slave配置: 1: 声明slave-of slaveof 192.168.0.102 2: 配置 ...
 - rel= "noopener"
			
rel= "noopener" <a href= "https://www.xiaogezi.cn/" target= "_blank" ...
 - 『转』How to Think About Your Career
			
开始工作的伊始,逐渐转载及阅读Medium上知名华裔设计师Julie Zhuo的文章,这是她在medium上的介绍:Product design VP @ Facebook. Lover of foo ...
 - 页面定制CSS代码初探(六):h2、h3 标题自动生成序号 详细探索过程
			
前言 最近在整理博客写作格式的规范,碰到一个问题:标题要不要加序号? 直到我碰到一个人这么说 手动维护编号实在是一件很闹心的事情, 如果位置靠前的某个段落被删除了, 那么几乎每个段落的编号都要手动修改 ...
 - Xcode 下“ did not have any applicable content ”分析及解决
			
问题的产生 a.新建项目时选的iPhone b.为了做成图片启动,按照惯例去掉了LaunchStoryboard的引用,建了个LaunchImage的资源,属性里随便勾了一个,找了张匹配的图拖了过去 ...
 - ZBrush2018中文版全球同步发售,终身授权
			
ZBrush 2018于2018.3.28发布了!这个我们期待已久的2018新版本等了几年,它终于来了! 不负众望,ZBrush 2018的这一次更新,简直炸裂,新功能真是太好用了!2018版是ZBr ...
 - [置顶]
        Elon Musk (伊隆·马斯克):无限的创想与意志的胜利
			
Elon Musk (伊隆·马斯克):无限的创想与意志的胜利 很多人说 Steve Jobs 很伟大,这一点我认同.但是,单纯从创造出的产物而言,Elon Musk 的成就毫无疑问远远超越 Steve ...
 - HDU 1002 A + B Problem II( 高精度加法水 )
			
链接:传送门 题意:A + B 高精度,板子题 /************************************************************************* & ...