【发布时间】:2017-01-20 03:41:08
【问题描述】:
所以我有一个 setRouteleaveHook 函数:
routerWillLeave(nextLocation) {
// return false to prevent a transition w/o prompting the user,
// or return a string to allow the user to decide:
console.log("prompt: ", this.props.prompt);
if (this.props.prompt) {
return "Are you sure you wish to navigate? Unsaved data will be lost. Try to use the 'next' button instead if moving to the next part.";
} else {
return true;
}
}
this.props.prompt 是存储中的变量。似乎当我在它的父级中更新它时,prompt 直到我下次访问它时才会改变。
有没有更好的方法来触发这些提示? (假设是父组件在做router.push)
【问题讨论】:
标签: javascript reactjs react-router react-redux