React/TypeScript 中如何使用privateRoutes
不多说直接丢代码
import { Route, Redirect, RouteProps } from 'react-router-dom';
import * as React from "react";
export interface PrivateRouteProps extends RouteProps {
component: React.ComponentType<any>
isSignIn: boolean
isIndex?:boolean
}
export const PrivateRoute = (props: PrivateRouteProps) => {
let { component: Component, isSignIn,...rest } = props;
return (
<Route
{...rest}
render={props => isSignIn == true ? <Component {...props} /> : <Redirect to='/login' />}
/>)
}
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭