简体   繁体   中英

how do I acces express params in my react component

I'm trying to create a React application using Express as a back-end

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.

Any suggestions on how I can access the:id in my React component?

Get the URL from the window.location object and parse it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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