首页 > 解决方案 > (替换 & 之间有什么区别) 在反应路由器中

问题描述

在 react-router (Redirect) 和 props.history.replace 中,它们执行相同的过程,当我按下返回页面时,我没有得到上一页,它们都是相同的,为了解决这个问题,我使用 push ,但为什么它们是一样的(替换 & )

标签: reactjsreact-router

解决方案


将历史视为堆栈数据结构。

TDLR栈是如何工作的以及push和replace的区别

const history = ['/login']
// history.push("/dashboard") ['/login', '/dashboard']
// history.replace('/dashboard') ['/dashboard']
// history.pop() []

推荐阅读