import React , { useEffect , useState } from 'react' ; import { Route , Redirect , RouteProps } from 'react-router-dom' ; import { useAppStore } from '../__internal' ; param props . component param props . rest export function PrivateRoute < T extends RouteProps = RouteProps , P = { } > ( props ) { let PrivateRouteComp = MyRoute as any ; let { component , ... rest } = props ; return < Route { ... rest } render = { ( ) => { return ( < PrivateRouteComp { ... props } / > ) ; } } />; } function MyRoute < T extends RouteProps = RouteProps , P = { } > ( { component , ... rest } ) { let authInfo = useAppStore ( "authInfo" ) ; let Comp = component as any ; useEffect ( ( ) => { } ) ; return authInfo ?. token ? < Comp { ... rest } / > : < Redirect to = { { pathname : '/login' , state : { from : rest . location } } } />; }