react-router - history.push 替换最后一条路径
问题描述
(同样适用于 react-router history.push
)
据我所知,如果我的 URL 不以 开头/
,那么它会附加到当前路径。
因此,例如,如果我当前的路径是https://google.com
并且如果我打电话history.pushState({},'','/test-path')
,那么 iI 将被定向到https://google.com/test-path
.
但是,对于我的路径不以 结尾的情况/
,它会用参数替换最后一位。
例如,如果我当前的路径是https://google.com/abc
, 和 call history.pushState({},'','test-path')
,那么我也会被定向到https://google.com/test-path
。
这是预期的行为吗?如果我想移至https://google.com/abc/test-path
from https://google.com/abc
,以下代码是实现此目的的最佳选择吗?
history.pushState({},'',location.pathname + '/test-path')
解决方案
推荐阅读
- android - 如何发送带有数据和列表的 POST 请求
在改造中遵循android中的MVP模式 - postgresql - 使用 PostgreSQL 的 AspNetCore.Identity:如何创建结构?
- node.js - 如何在使用 NodeJS、Express 和 mongodb 更新旧表单数据之前检索旧表单数据!Ejs是模板吗?
- javascript - 如何用 ReactJS 中的变量替换查询中的参数中的字符串
- excel - Excel:返回/自动换行/firstpage.footer中的第二行或更多行?
- ios - 选择退出 SceneDelegate 后 Xcode 未调用应用程序委托
- java - jaxrs 应用程序中的公共资源不起作用
- python - Python - Pandas - 合并两个具有不同时间戳频率的 DataFrame
- regex - 将非捕获组添加到字符类
- c# - UTF-8 字符转换为 c# webserver