当前位置:网站首页>umi 路由拦截(简单粗暴)
umi 路由拦截(简单粗暴)
2022-07-03 03:12:00 【拾忆@y】
一、业务场景:
最近在使用umi进行开发,其中在做导航路由渲染的时候遇到了一些坑,为了大家后面遇到和我一样的问题,给大家分享一下
二、解决方案:
先添加一个高阶组件,跟所有组件同级,再配置路由的地方添加配置 wrappers: [‘@/wrappers/auth’],怕大家不理解,下面有图。
三、具体实现步骤
1、在src的目录下,和page同级,新建一个wrappers文件夹(这个名称是固定的),在文件夹下新建 Auth.tsx文件,
2、在文件里面的写入以下内容:
import {Redirect} from 'umi'
export default function Auth(props:any) {
//获取本地缓存 localStorage的值
const isLogin = localStorage.getItem('role')
//如果这个值存在就返回正常内容
if(isLogin){
return (
<div>
{props.children}
</div>
);
}else {
//如果这个值存在就重定向到登录页
console.log('跳登录')
return ( <Redirect to='/login' />)
}
}
3、在配置路由的地方加上 wrappers: [‘@/wrappers/auth’],需要拦截的都必须添加,如图
四、效果展示

今天的分享到此结束,欢迎小伙伴们一起交流
边栏推荐
- Agile certification (professional scrum Master) simulation exercises
- ComponentScan和ComponentScans的区别
- What does it mean when lambda is not entered?
- The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
- The process of connecting MySQL with docker
- PAT乙级常用函数用法总结
- [combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
- 别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
- idea 加载不了应用市场解决办法(亲测)
- C#通用接口调用
猜你喜欢

Three.js本地环境搭建

I2C subsystem (III): I2C driver

I2C 子系统(三):I2C Driver

用docker 连接mysql的过程

C语言初阶-指针详解-庖丁解牛篇

idea 加载不了应用市场解决办法(亲测)

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)

Left connection, inner connection

The idea cannot be loaded, and the market solution can be applied (pro test)

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
随机推荐
js根据树结构查找某个节点的下面的所有父节点或者子节点
Kubernetes family container housekeeper pod online Q & A?
Basic information of Promethus (I)
MySql实战45讲【SQL查询和更新执行流程】
Model transformation onnx2engine
Do you really understand relays?
监听对象中值变化及访问
@Accessors annotation function specifies that the prefix follows the hump naming
C#通用接口调用
Find the storage address of the elements in the two-dimensional array
Le processus de connexion mysql avec docker
基于Qt的yolov5工程
L'index des paramètres d'erreur est sorti de la plage pour les requêtes floues (1 > Nombre de paramètres, qui est 0)
Parameter index out of range (1 > number of parameters, which is 0)
左连接,内连接
Force freeing memory in PHP
From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
Docker install redis
Check log4j problems using stain analysis