Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react路由的高阶组件PrivateRoute #47

Open
duxinyues opened this issue Sep 9, 2021 · 0 comments
Open

react路由的高阶组件PrivateRoute #47

duxinyues opened this issue Sep 9, 2021 · 0 comments

Comments

@duxinyues
Copy link
Owner

import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { fakeAuth } from '../utils/fake-auth';
const PrivateRoute = ({ component: Component, ...rest }) => {
    return (
        <Route
            {...rest}
            render={props => (fakeAuth.authenticate()) ? (<Component {...props} />) : (
                <Redirect to={{
                    pathname: "/login",
                    state: { from: props.location }
                }} />
            )}
        ></Route>
    )
}
export default PrivateRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant