当前位置:网站首页>UMI route interception (simple and rough)
UMI route interception (simple and rough)
2022-07-03 03:15:00 【Recall @y】
One 、 Business scenario :
Recently in use umi Development , Some pits were encountered when rendering navigation routes , For everyone to meet the same problem as me later , Let me share with you
Two 、 Solution :
First add a high-level component , At the same level as all components , Add configuration where you want to configure the route wrappers: [‘@/wrappers/auth’], I'm afraid we don't understand , Here is a picture .
3、 ... and 、 Specific implementation steps
1、 stay src Under the directory of , and page At the same level , Create a new one wrappers Folder ( The name is fixed ), Create a new Auth.tsx file ,
2、 Write the following contents in the file :
import {Redirect} from 'umi'
export default function Auth(props:any) {
// Get local cache localStorage Value
const isLogin = localStorage.getItem('role')
// If this value exists, it will return to the normal content
if(isLogin){
return (
<div>
{props.children}
</div>
);
}else {
// If this value exists, redirect to the login page
console.log(' Skip login ')
return ( <Redirect to='/login' />)
}
}
3、 Add wrappers: [‘@/wrappers/auth’], What needs to be intercepted must be added , Pictured
Four 、 Effect display
This is the end of today's sharing , Welcome friends to communicate together
边栏推荐
- I2C 子系统(三):I2C Driver
- Spark on yarn resource optimization ideas notes
- Pat class B common function Usage Summary
- 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
- I2C subsystem (II): I3C spec
- The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
- 二维数组中的元素求其存储地址
- Use of check boxes: select all, deselect all, and select some
- The XML file generated by labelimg is converted to VOC format
- Distributed transaction
猜你喜欢
PAT乙级“1104 天长地久”DFS优化思路
Pytoch configuration
Pytorch配置
Segmentation fault occurs during VFORK execution
Vs 2019 configure tensorrt to generate engine
Limit of one question per day
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
Do you really understand relays?
Creation and destruction of function stack frame
随机推荐
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
Why does thread crash not cause JVM crash
I2C subsystem (I): I2C spec
基于Qt的yolov5工程
模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
Pat class B "1104 forever" DFS optimization idea
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
为什么线程崩溃不会导致 JVM 崩溃
Chart. JS multitooltip tag - chart js multiTooltip labels
Left connection, inner connection
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)
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
解决高并发下System.currentTimeMillis卡顿
Use of check boxes: select all, deselect all, and select some
Agile certification (professional scrum Master) simulation exercises
Pytoch configuration
Sous - système I2C (IV): débogage I2C
ComponentScan和ComponentScans的区别
The XML file generated by labelimg is converted to VOC format