📜  反应受保护的路线打字稿代码示例

📅  最后修改于: 2022-03-11 14:48:32.305000             🧑  作者: Mango

代码示例1
import * as React from 'react';
import {
    Route, 
    Redirect,
    RouteProps,
    RouteComponentProps
} from "react-router-dom";

interface PrivateRouteProps extends RouteProps {
    isAuthenticated: boolean;
  // Would reccommend this comes from a global state manager
  // such as redux, shown using basic props here
}

export class PrivateRoute extends Route {
    render() {
        return (
             {
                if(!this.props.isAuthenticated) {
                    return 
                } 

                if(this.props.component) {
                    return React.createElement(this.props.component);
                } 

                if(this.props.render) {
                    return this.props.render(props);
                }
            }} />
        );
    }
}

// How To Use Them :::::

      // OR
 (
       
    )} 
/>