简体   繁体   English

我如何在我的反应组件中访问表达参数

[英]how do I acces express params in my react component

I'm trying to create a React application using Express as a back-end我正在尝试使用 Express 作为后端创建一个 React 应用程序

I have this route set up in express我在快递中设置了这条路线

 app.get('/manage/:id', (req, res) => {
    // redirect to react application
 });

I want to be able to make my React component get data from my database (to then use it), but I need the id for that.我希望能够让我的 React 组件从我的数据库中获取数据(然后使用它),但我需要这个 id。

Any suggestions on how I can access the:id in my React component?关于如何在我的 React 组件中访问:id 的任何建议?

Get the URL from the window.location object and parse it:从 window.location object 获取 URL 并解析它:

UPDATE: window.location.pathname.split('/').reverse()[0]更新: window.location.pathname.split('/').reverse()[0]

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

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