【发布时间】:2016-12-01 15:15:00
【问题描述】:
我正在使用最新版本的 react 路由器 (^3.0.0)。
我正在尝试使用 onEnter 钩子在我的一个组件中中止转换:
var AuthorPage = React.createClass({
statics: {
onEnter: function(nextState, replace, callback) {
replace('/');;
//hashHistory.replace('/');
}},...
当我使用 onEnter 钩子的 replace 方法时,它工作正常(组件确实变回了我的主应用程序组件),但 URL 保持不变: http://localhost:9005/#/authors 而不是 http://localhost:9005/#。
另一方面,当我使用 hashHistory.replace 方法时,组件和 URL 都会正确更改(使用 react-router 的 hashHistory)。
我想澄清两点:
- 如果 replace 方法不更改我的 URL,而它确实将组件更改回我想要的内容,我为什么要使用它?
- hashHistory.replace 方法是否被认为是执行中止转换到特定页面的合适方法?
谢谢
【问题讨论】:
标签: reactjs react-router browserify