简体   繁体   中英

Express Routes params to define react page components

I am learning Express.js , this is my case, i have 2 urls

/security/1

/security/2

The answer to that request will be the following, depending on the answer, the "/security/{id}" will return a Web page that will show and enable a certain number of "elements".

app.get('/security/:id', (req, res) => {
  setTimeout(
    () =>
      res.send({
        access: req.params.id === '1' ? ['EDIT', 'DELETE', 'VIEW', 'ADD'] : ['VIEW'],
      }),
    Math.floor(Math.random() * 2000 + 100)
  );
});

My question is now that i have flagged the elements based on the request parameter, how can i render my react page ( for example index.js ) flagging these elements

I would appreciate any example or code answer helping me to figure it out the approach

I did not fully understand your question but you can make request from your frontend React page and based on the result you can render whatever you want.

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