import { Spin } from "antd";
import { Suspense } from "react";
import { Navigate } from "react-router-dom";
import KeepAlive from 'react-activation'
function AuthRoute(props: any) {
const token = localStorage.getItem("token");
let template = <Navigate to='/' replace>Navigate>;
if (token || !props.auth) {
template = <KeepAlive autoFreeze={false} when={true} key={props.id} id={props.id}>
<Suspense fallback={<div style={spinStyle}><Spin />div>}>{props.children}Suspense>
template = <Suspense fallback={<div style={spinStyle}><Spin />div>} >{props.children}Suspense>
使用方式
![](https://1000bd.com/contentImg/2024/03/19/113631983.png)