标签:end 相同 const ext cat nec top out vat
demo
import React from ‘react‘;
import {Route,Redirect} from ‘react-router-dom‘
import {connect} from ‘react-redux‘
import { PropTypes } from ‘prop-types‘
const PrivateRoute = ({ component: Component, auth,...rest }) => (
<Route
{...rest}
render={
(props) =>
(auth.isAuthenticated === true
? <Component {...props} />
: <Redirect to=‘/login‘ />
)} />
)
PrivateRoute.propTypes = {
auth: PropTypes.object.isRequired
}
const mapStateToProps = state => ({
auth: state.auth,
})
export default connect(mapStateToProps)(PrivateRoute);
据用户的auth状态,我们将渲染Redirect
或渲染组件
以下是我们PrivateRoute
组件的要求。
标签:end 相同 const ext cat nec top out vat
原文地址:https://www.cnblogs.com/guangzhou11/p/10337860.html