【发布时间】:2017-03-07 08:28:49
【问题描述】:
当我输入两个不同的组件时,我需要检查 Facebook 的到期日期和当前日期。 Dashboard 和 Pages。两者都有这个:
componentWillMount() {
const { linkedAccount, clearLinkedAccounts, getFacebookPages } = this.props
const now = moment().format('YYYY-MM-DD HH:mm:ss')
if (linkedAccount) {
if (now < linkedAccount.expiresIn) {
getFacebookPages()
} else {
clearLinkedAccounts()
}
}
}
componentWillUnmount() {
const { linkedAccount, clearLinkedAccounts } = this.props
const now = moment().format('YYYY-MM-DD HH:mm:ss')
if (linkedAccount && now > linkedAccount.expiresIn) {
clearLinkedAccounts()
}
}
但只有在手动刷新页面时,clearLinkedAccounts() 才会被执行,通过运行componentWillMount,但在离开它之前,它不会。如有必要,我希望在进入另一条路线之前执行它。
【问题讨论】:
-
你也可以提供 react 路由器代码吗?
标签: reactjs components