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 ...
随机推荐
- hdoj--3062--party(2-sat 可行解)
Party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- NEU 1009 Happiness Hotel
1009: Happiness Hotel 时间限制: 1 Sec 内存限制: 128 MB提交: 173 解决: 19[提交][状态][讨论版] 题目描述 The life of Little ...
- matlab基本语法
MATLAB基本语法 点乘运算 , 常与其他运算符 点乘运算,常与其他运算符联合使用(如.\) 矩阵生成 矩阵生成 向量生成或子阵提取本节将会介绍一些MATLAB的基本语法的使用. 持续更新... 在 ...
- sqlserver数据文件位置如何迁移
亲测有效的一种方式: 1.对应的数据库脱机 2.迁移物理文件 3.删除原有实例 4.附加
- 五步完成一个 VSCode 扩展(插件)开发
第一步: 安装扩展生成器 npm install -g yo generator-code vsce 第二步: 初始化一个 Hello World 扩展 yo code 图来自 CN-VScode-D ...
- 一个基于Vue.js+Mongodb+Node.js的博客内容管理系统
这个项目最初其实是fork别人的项目.当初想接触下mongodb数据库,找个例子学习下,后来改着改着就面目全非了.后台和数据库重构,前端增加了登录注册功能,仅保留了博客设置页面,但是也优化了. 一.功 ...
- vue项目踩坑-引入bootstrap
1.下载jquery; npm install jquery --save-dev 2.在webpack.base.conf.js中添加如下内容: var webpack = require('web ...
- Appstore排名前十的程序员应用软件
程序员又名程序猿,苦逼劳累的代名词,曾经一个朋友这么开玩笑说,如果你是富二代,你当程序员就是脑残,如果你是穷二代,当程序员的话,死的时候一定是趴键盘. 程序员 哦,可怜的程序员.在那山的这边海的那边有 ...
- RabbitMQ学习笔记(2)----RabbitMQ简单队列(Hello World)的使用
1. 简单队列结构图 2. 引入依赖 pom.xml文件 <dependency> <groupId>com.rabbitmq</groupId> <arti ...
- Python多进程原理与实现
Date: 2019-06-04 Author: Sun 1 进程的基本概念 什么是进程? 进程就是一个程序在一个数据集上的一次动态执行过程.进程一般由程序.数据集.进程控制块三部分组成.我们编写 ...