简体   繁体   English

如何在React-router中添加状态

[英]How to add State in React-router

When pressing the icon i want my application to navigate me to localhost:8080/editrevision+700 (700 being the id of that specific item) 当按下图标时,我希望我的应用程序将我导航到localhost:8080 / editrevision + 700(700是该特定项目的ID)

<Menu.Item className="edit" 
   as={Link} 
   to="/editrevision" + {revisionItem.id}> 
   <i className="far fa-edit"/> 
</Menu.Item>

i keep getting syntax error on this, all suggestions are very appreciated. 我不断收到语法错误,所有建议都非常感谢。

The problem is the syntax of the to . 问题是to的语法。 You should wrap the whole value in curly braces. 您应该将整个值括在花括号中。

The best way to pass id a parameter is as /editrevision/700 . 传递id参数的最佳方法是/editrevision/700 And, when you set the route, set its path as /editrevision/:id . 并且,当您设置路线时,请将其路径设置为/editrevision/:id The id can be retrieved through this.props.match.params.id . 可以通过this.props.match.params.id检索this.props.match.params.id

<Menu.Item className="edit" 
   as={Link} 
   to={"/editrevision" + revisionItem.id}
   > 
       <i className="far fa-edit"/> 
</Menu.Item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM