react 路由权限

TypeScript 复制代码
import {  Spin } from "antd";
import { Suspense } from "react";
import { Navigate } from "react-router-dom";
import KeepAlive from 'react-activation'
function AuthRoute(props: any) {
    const spinStyle = {
        width: '100%',
        height: '100%',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center'
    }
    const token = localStorage.getItem("token");

    let template = <Navigate to='/' replace></Navigate>;

    if (token || !props.auth) {
        if (props.id) {
            template = <KeepAlive autoFreeze={false} when={true} key={props.id} id={props.id}>
                <Suspense fallback={<div style={spinStyle}><Spin /></div>}>{props.children}</Suspense>
            </KeepAlive>
        } else {
            template = <Suspense fallback={<div style={spinStyle}><Spin /></div>} >{props.children}</Suspense>
        }

    }
    return template
}
export default AuthRoute

使用方式

相关推荐
小嘟嚷ovo17 分钟前
h5,原生html,echarts关系网实现
前端·html·echarts
十一吖i1 小时前
Vue3项目使用ElDrawer后select方法不生效
前端
只可远观1 小时前
Flutter目录结构介绍、入口、Widget、Center组件、Text组件、MaterialApp组件、Scaffold组件
前端·flutter
周胡杰1 小时前
组件导航 (HMRouter)+flutter项目搭建-混合开发+分栏效果
前端·flutter·华为·harmonyos·鸿蒙·鸿蒙系统
敲代码的小吉米1 小时前
前端上传el-upload、原生input本地文件pdf格式(纯前端预览本地文件不走后端接口)
前端·javascript·pdf·状态模式
是千千千熠啊1 小时前
vue使用Fabric和pdfjs完成合同签章及批注
前端·vue.js
da-peng-song1 小时前
ArcGIS Desktop使用入门(二)常用工具条——数据框工具(旋转视图)
开发语言·javascript·arcgis
九月TTS2 小时前
TTS-Web-Vue系列:组件逻辑分离与模块化重构
前端·vue.js·重构
我是大头鸟2 小时前
SpringMVC 内容协商处理
前端
Humbunklung2 小时前
Visual Studio 2022 中添加“高级保存选项”及解决编码问题
前端·c++·webview·visual studio