react router 路由守卫
程序员文章站
2022-03-26 14:10:09
...
import {Route,Redirect}from “react-router-dom”
const PrivateRoute = ({component:Component, ...rest}) =>(
<Route
{...rest}
render={props=>{
return isLogin ?
<Component {...props}>
:
<Redirect
to={{
pathname:'/login',
state:{redirect:props.location.pathname}
}}
>
}}
/>
)