react-router-dom-链接和history.push之间的区别?

Hiago Bonamelli

我了解href和link之间的区别。

但是我想知道在history.push中使用链接和withrouter之间的区别吗?如果我已经访问过该页面,history.push是否会在缓存中检索该页面?

使用链接:

<Link className="btn btn-primary" onClick={logout} to="/">
 Log out
</Link>

使用历史记录:

constructor(props) {
        super(props);
        this.handleLogout = this.handleLogout.bind(this);
    };

    handleLogout(e) {
        const { history } = this.props;
        logout()
        history.push("/");

    }
<button type="button" onClick={this.handleLogout}>Log out</button>
weibenfalk

使用链接,您可以通过包装例如按钮来导航到另一个“页面”,并在单击时进行重定向。通常这是您可能想要做的。但是在某些情况下,您希望以编程方式导航到另一个“页面”。例如,当您的应用程序发生更改时,与单击按钮或链接无关。

因此,您可以使用history.push以编程方式更改url,而无需单击按钮或链接。=)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

react-router 4.0,react-router-dom和react-router-redux有什么区别?

react-router-redux中的“ push”方法和react-router中的“ browserHistory”之间有什么区别?

React Redux和react-router-dom

react-router-dom链接不起作用

混淆react-router-dom和react-router-redux

在firefox中react-router-dom的链接不起作用

在刷新/直接链接上从API和react-router-dom获取数据

react-router-dom链接onclick获取路径

react-router-dom链接不会更新页面

链接不使用React DOM Router重定向

npm install react-router-dom和npm install --save react-router-dom命令之间的区别

react-router-dom <链接>未更新页面

react-router-dom和Typescript不显示组件

带有react-router-dom链接的SpeedDialAction

react-router-dom嵌套的路由和重定向

History.Push链接到带有React Router的新选项卡

react-router-dom链接-悬停时隐藏URL

如何使用CSS在React Router Dom中选择链接标签?

使用react-router-dom的history.push

如何使用React正确设置react-router-dom链接

带有 Reactstrap 和 React Router Dom 的 Active NavLink

可重用的 react-router-dom 链接 hrefs

react-router-dom中location.pathname和match.url的区别?

React-router-dom:链接无法编译

Antd Anchor 的链接和 React Router 的链接之间的冲突

react-router-dom 链接不会转到页面内容

`yarn add react-router-dom` 和 `yarn add @types/react-router-dom` 有什么区别?

React-router-dom 和 TypeScript

主页和侧页的 react-router-dom 路径