当前位置:网站首页>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
边栏推荐
- The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
- MySql实战45讲【SQL查询和更新执行流程】
- Pat class B common function Usage Summary
- MySQL practice 45 lecture [row lock]
- Last update time of all sqlserver tables
- MySQL practice 45 lecture [transaction isolation]
- From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
- I2C 子系统(四):I2C debug
- @Accessors注解作用指定前缀遵守驼峰命名
- MySql实战45讲【全局锁和表锁】
猜你喜欢
Docker install redis
VS 2019 配置tensorRT生成engine
MySql实战45讲【全局锁和表锁】
el-tree搜索方法使用
I2C 子系统(一):I2C spec
Three. JS local environment setup
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
I2C subsystem (III): I2C driver
随机推荐
C # general interface call
The series of hyperbolic function in daily problem
一文带你了解 ZigBee
open file in 'w' mode: IOError: [Errno 2] No such file or directory
VS 2019配置tensorRT
Vs Code configure virtual environment
Docker install MySQL
基于Qt的yolov5工程
I2C subsystem (II): I3C spec
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
Use of El tree search method
Find the storage address of the elements in the two-dimensional array
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
Use of check boxes: select all, deselect all, and select some
The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
docker安装redis
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
3D drawing example
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
C#通用接口调用