如何隐藏在路径中传递的id作出反应?

时间:2017-07-21 11:34:56

标签: reactjs

如何隐藏ID显示在网址中?

<Route path="/AddShop/:id" component = {AddShop} />

1 个答案:

答案 0 :(得分:0)

您可以在链接中使用状态

路线

<Route exact={true} path="/post_view" component={PostView} />

链接

<Link 
                to={{
                  pathname: `/post_view`,
                  state: {
                    id: item.id
                  }
                }}
                className="btn btn-sm btn-primary pull-right">
                view
            </Link>

查看页面

const post_id = props.location.state.id;

唯一的限制是当您共享链接时,状态将没有该ID