到目前为止,我已经阅读了很多关于 react-router v4 和 npm 历史库的内容,但似乎没有一个对我有帮助。
当使用 history.push() 方法更改 url 时,我的代码按预期运行,直到它应该导航并执行简单的重定向。URL 正在更改为指定的路由,但未在按钮推送时进行重定向。先谢谢了,还在学习react-router...
我希望按钮按下可以在没有 {forceRefresh:true} 的情况下进行简单的重定向,然后重新加载整个页面。
import React from 'react';
import createBrowserHistory from 'history/createBrowserHistory';
const history = createBrowserHistory({forceRefresh:true});
export default class Link extends React.Component {
onLogout() {
history.push("/signup");
}
render() {
return(
<div>
<h1>Your Links</h1>
<button onClick={this.onLogout.bind(this)}>Log Out</button>
</div>
)
}
}