如何解决history.push 替换最后一条路径
(同样适用于 react-router history.push
)
据我所知,如果我的 URL 不以 /
开头,那么它会附加到当前路径。
例如,如果我当前的路径是 https://google.com
,如果我调用 history.pushState({},'','/test-path')
,那么我将被定向到 https://google.com/test-path
。
但是,对于我的路径不以 /
结尾的情况,它用参数替换最后一位。
例如,如果我当前的路径是 https://google.com/abc
,并且调用 history.pushState({},'test-path')
,那么我也会被定向到 https://google.com/test-path
。
这是有意的行为吗?
如果我想从 https://google.com/abc/test-path
转到 https://google.com/abc
,以下代码是实现此目的的最佳选择吗?
history.pushState({},location.pathname + '/test-path')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。