首页 > 解决方案 > 有什么方法可以从 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

标签: reactjsurlhyperlinkreact-router-dom

解决方案


防止在 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');

推荐阅读