小编Joh*_*ohn的帖子

React history.push()正在更新url但不在浏览器中导航到它

到目前为止,我已经阅读了很多关于react-router v4和npm历史库的内容,但似乎没有人帮助我.

我的代码按预期运行,直到它应该导航并在使用history.push()方法更改url时执行简单的重定向.URL正在更改为指定的路由,但不会在按钮上执行重定向.在此先感谢,仍在学习反应路由器......

我想按钮按钮在没有{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>
      )
  }
}
Run Code Online (Sandbox Code Playgroud)

history.js react-router-v4

42
推荐指数
5
解决办法
3万
查看次数

标签 统计

history.js ×1

react-router-v4 ×1