2 回答
TA贡献1790条经验 获得超9个赞
问题在这里:
const RefreshRoute = ({ component: Component, ...rest }) => {
const canGo=this.props.loggedIn;
您正在props使用破坏输入{ component: Component, ...rest }。因此,该属性loggedIn将位于其中rest.loggedIn:
const RefreshRoute = ({ component: Component, ...rest }) => {
const canGo = rest.loggedIn;
否则,您可以loggedIn在分解后的参数内部显式并使用它:
const RefreshRoute = ({ component: Component, loggedIn, ...rest }) => {
const canGo = loggedIn;
TA贡献1808条经验 获得超4个赞
因此,在功能组件中您无需this.props更改:
const RefreshRoute = ({ component: Component, ...rest }) => {
const canGo=this.props.loggedIn; // props is not bound to this
...
}
至:
const RefreshRoute = (props) => {
const canGo = props.loggedIn
}
或您的情况:
const RefreshRoute = ({ component: Component, ...rest }) => {
const canGo = rest.loggedIn
}
添加回答
举报