reactjs - 有什么方法可以从 URL 中隐藏某些 PARAMETERS 吗?我正在使用链接。[反应]
问题描述
我<Link to={/name/id} >name</Link>
用来改变路线;
我有一个路由设置,<Route path="/name/:id" component={Name} />
因为我正在获取数据
componentDidMount() {
this.props.fetchName(this.props.match.params.id);
}
但现在我在URL上显示了Id,我不想在URL上显示Id。
所以,想知道是否有任何解决方法可以不在URL上显示Id
解决方案
防止在 URL 上显示的唯一方法是使用,redux
以便您可以id
在导航到页面之前将其保存在商店中,并且在导航到页面后,您只需从商店中获取它。或者您可以通过使用来实现它sessionStorage
,您将 id 保存在会话存储中
sessionStorage.setItem('my-id', id);
//navigate to other page
//then in other page just use the code below to get that id from session storage.
sessionStorage.getItem('my-id');
推荐阅读
- wordpress - 如何在 Woocommerce 订单页面中添加另一封电子邮件并使其也应接收电子邮件?
- kubernetes - Kubernetes 浪费资源
- api - npm request - 用于 twitch 数据的自定义 HTTP 标头
- spring - 获取 java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder 更新 Spring Cloud 版本到 Brixton.SR6 后
- javascript - ReactJS - 如何将字符串中的html元素列表作为html元素返回
- elasticsearch - 将多类型索引迁移到单类型索引
- node-red - 无法使用 Switch 节点可视化我的数据
- android - Android - Kotlin:在扩展应用程序的类中实例化一个对象并在所有活动中使用它
- javascript - vue组件上的js函数
- javascript - SAPUI5 表在获取选定行数据时出现多选错误