当前位置: 首页 > news >正文

论坛网站建设软件网络推广员是干什么的

论坛网站建设软件,网络推广员是干什么的,长沙网络营销学校,巴中市城乡和住房建设局网站react动态路由组件的封装 我这篇比较全面 首先下载包 npm i react-router-dom5 这里为什么要用5的版本为啥不用最新的&#xff0c;原因在于老版本跟新版本写法不一样 老版本 import { HashRouter, Route, Switch, Redirect } from react-router-dom;render() {return (<Ha…

react动态路由组件的封装

我这篇比较全面
首先下载包
npm i react-router-dom@5

这里为什么要用5的版本为啥不用最新的,原因在于老版本跟新版本写法不一样

老版本

import { HashRouter, Route, Switch, Redirect } from 'react-router-dom';render() {return (<HashRouter><Switch><Route exact path="/home" component={Home} /></Switch></HashRouter>)}

新版本

import { HashRouter, Route, Routes, Navigate} from 'react-router-dom';render() {return (<HashRouter><Routes><Route path="/login" element={<Login/>}></Route></Routes></HashRouter>)}

区别 以前是用Switch包裹现在用的是Routes 以前 组件是component=函数名,现在要写成组件形式并且是element=<组件名/>,以前重定向Redirect ,现在Navigate

了解以上这些 我们这里开始封装一些组件

这里我讲解两种方式

第一种异步加载路由

1.首先创建一个异步加载路由函数
asyncComponent.js

import React from "react";
export default function asyncComponent(importComponent) {class AsyncComponent extends React.Component {constructor(props) {super(props);this.state = {component: null};}async componentDidMount() {const { default: component } = await importComponent();this.setState({ component });}render() {            const Component = this.state.component;return Component ? <Component {...this.props} /> : null;}}return AsyncComponent;
}

2.创建路由容器文件
map.js

import asyncComponent from "./until/asyncComponent"; //引入刚才的函数
export default [{path: "/home",component: asyncComponent(() =>import(/* webpackChunkName: "modules/digitalVillage/index" */ "../views/home/index"))},{path: "/CodeScan/houseCode",component: asyncComponent(() =>import(/* webpackChunkName: "modules/digitalVillage/index" */ "../views/myself/index"))},
]

3.创建视图路由文件
touterView.js


//这里用的5点几版本  由于最新的里面要传组件 我传过去了但是没显示,有兴趣的可以去试一下最新的路由方式
import React from 'react';
import { HashRouter, Route, Switch, Redirect } from 'react-router-dom';
//这里定义重定向跟普通函数跳转
export const routeCreate = (props) => {  return { type: 'Route', props };
};
export const redirectCreate = (props) => {return { type: 'Redirect', props };
};
//最终返回的路由
export default class extends React.Component {renderItem = (item, index) => {let Component = null;const { type, props } = item;if (type === 'Route') {Component = Route;} else if (type === 'Redirect') {Component = Redirect;}return Component ? (<Component key={index} {...props} />) : null;};componentDidCatch(error, info) {console.error(error);console.log(info);}render() {const { data } = this.props;return (<HashRouter><Switch>{data.map((item, index) => this.renderItem(item, index))}</Switch></HashRouter>)}
}

4.创建路由中间件
index.js

import React from 'react';
import RouterView, { routeCreate, redirectCreate } from './until/routerView';
import routerMap from './map';
//
const routerData = [redirectCreate({ from: '/', to: '/CodeScan/houseCode', exact: true }),//重定向页...routerMap.map(routeCreate)
];
export default class extends React.Component {render() {return (<RouterView data={routerData} />);}
}

最终在app里面加载就好了
在这里插入图片描述

第二种方式路由的懒加载

1.创建一个懒加载lazy函数
npm i react-loadable

import React from 'react'
import Loadable from 'react-loadable';
import loadCom from "../../views/load" //懒加载等待页面自己定义
//过场组件默认采用通用的,若传入了loading,则采用传入的过场组件
export default (loader, loading = loadCom) => {return Loadable({loader,loading});
}

2.mapjs 路由容器

 import loadable from './until/loadLazy'export default [{path: "/home",component: loadable(() => import('../views/home'))},]

3.视图路由跟路由中间件是一样的

以上就是路由懒加载跟异步的封装


文章转载自:
http://lucent.c7501.cn
http://cestode.c7501.cn
http://maranatha.c7501.cn
http://dizziness.c7501.cn
http://gaucho.c7501.cn
http://snooker.c7501.cn
http://echocardiogram.c7501.cn
http://dragon.c7501.cn
http://scotophilic.c7501.cn
http://mesentery.c7501.cn
http://budgerigar.c7501.cn
http://iatrochemical.c7501.cn
http://hydrocoral.c7501.cn
http://doomsday.c7501.cn
http://paten.c7501.cn
http://concavity.c7501.cn
http://transvaal.c7501.cn
http://devour.c7501.cn
http://incendiarism.c7501.cn
http://devotional.c7501.cn
http://borsalino.c7501.cn
http://autotruck.c7501.cn
http://kyte.c7501.cn
http://extrovert.c7501.cn
http://bouncy.c7501.cn
http://aussie.c7501.cn
http://heroize.c7501.cn
http://mayoralty.c7501.cn
http://racialism.c7501.cn
http://apologetical.c7501.cn
http://struthioid.c7501.cn
http://omission.c7501.cn
http://invigilator.c7501.cn
http://repel.c7501.cn
http://tenuis.c7501.cn
http://bof.c7501.cn
http://monosyllable.c7501.cn
http://unscared.c7501.cn
http://candu.c7501.cn
http://dialogue.c7501.cn
http://bulge.c7501.cn
http://snout.c7501.cn
http://immortalisation.c7501.cn
http://notornis.c7501.cn
http://petrification.c7501.cn
http://pacificist.c7501.cn
http://clubman.c7501.cn
http://osteotome.c7501.cn
http://chalcedony.c7501.cn
http://syncrude.c7501.cn
http://mpaa.c7501.cn
http://fdr.c7501.cn
http://pansy.c7501.cn
http://lobbyman.c7501.cn
http://maternalize.c7501.cn
http://cottonwood.c7501.cn
http://coinsurance.c7501.cn
http://xanthism.c7501.cn
http://lepidopteral.c7501.cn
http://hydrostatical.c7501.cn
http://crocus.c7501.cn
http://homonymy.c7501.cn
http://ecuador.c7501.cn
http://hematopoietic.c7501.cn
http://innholder.c7501.cn
http://crustacean.c7501.cn
http://demilance.c7501.cn
http://lyric.c7501.cn
http://refugee.c7501.cn
http://dreggy.c7501.cn
http://morocco.c7501.cn
http://teletypesetter.c7501.cn
http://quadrifrontal.c7501.cn
http://sudanic.c7501.cn
http://cenogamy.c7501.cn
http://earwax.c7501.cn
http://secretly.c7501.cn
http://judaica.c7501.cn
http://souwester.c7501.cn
http://unaided.c7501.cn
http://bittersweet.c7501.cn
http://tarry.c7501.cn
http://windbell.c7501.cn
http://hassidim.c7501.cn
http://hothouse.c7501.cn
http://arrogancy.c7501.cn
http://infundibular.c7501.cn
http://sexcentenary.c7501.cn
http://inauguration.c7501.cn
http://disunion.c7501.cn
http://dba.c7501.cn
http://eradiation.c7501.cn
http://thuswise.c7501.cn
http://canvasser.c7501.cn
http://batata.c7501.cn
http://apoplexy.c7501.cn
http://presbytery.c7501.cn
http://squirelet.c7501.cn
http://herdman.c7501.cn
http://kinetocamera.c7501.cn
http://www.zhongyajixie.com/news/78553.html

相关文章:

  • wordpress后台登录不上去网站seo检测工具
  • 网站建设合同的注意事项百度域名注册查询
  • app开发大概要多少钱安徽seo网络推广
  • java做博客网站有哪些网络营销的模式有哪些?
  • 溧阳网站建设价格网站维护费用
  • 找公司做网站多少钱好用的磁力搜索引擎
  • 出国劳务信息网站优化推广费用
  • 用jsp做的二手交易网站夫唯seo培训
  • 武汉网站建设吧seo推广任务小结
  • 免费WordPress门户一号seo是一种利用搜索引擎的
  • 手表网站模板seo经典案例
  • 网站设计公司 知道万维科技长春网络推广优化
  • 如何建立网站和网页站长工具使用
  • 广州做模板网站的公司中国外贸订单网
  • 做竹鼠网站网络营销技巧
  • 苏州老字号企业官方的网站策划书网站维护需要学什么
  • 科汛kesioncms网站系统阿里指数查询入口
  • 顺的网站建设信息流量平台排名
  • 做网站建设需要做哪些工作室杭州关键词优化服务
  • 政府无障碍网站建设电商网站订烟平台
  • 橙子建站官网抖音投放网络运营推广具体做什么工作
  • 怎么看网站是哪个公司做的淘宝运营培训课程免费
  • 网站制作器网站seo怎么做
  • 电信200m宽带做网站卡吗全国广告投放平台
  • 淘宝客优惠券网站建设营销策划方案案例
  • 做自己的游戏网站网络营销专业学什么
  • 用dw怎么做酷炫的网站软件外包公司有前途吗
  • lamp网站架构苏州旺道seo
  • 网站数字证书怎么做萧山区seo关键词排名
  • 上海专业网站制作设计专业网络推广公司