0

i'm using express to make a electronic document management (EDMS) in node.js.

After the user login, I'll have a simple box, where he's chosee between two options: a. search XML files b. search Other Documents files

is there a way to create specific routing for, if he chooses to go only with XML, all links i'll be under that routing?

Something like xml/home/ and otherDocuments/home/ and the rest of the methods ill be xml/something and otherDocuments/something?

rmbrandao
  • 3
  • 1
  • 2
  • Do you mean you want your router in express to handle the prefix for you? `const router = express.Router(); router.get('/foo', /**/); app.use('/xml', router);` - now the /foo handler is reached via `/xml/foo`. – cbr Mar 10 '20 at 13:19
  • or do you just mean that you want `res.redirect()` to get the prefix for you? – cbr Mar 10 '20 at 13:20
  • I mean that my router handle the prefix, once the xml visualization is selected, all the links will be redirect/prefix to a ```xml/foo```, or if otherDocs is selected, all the links will be to ```otherDocs/foo```, based on the first selection after login – rmbrandao Mar 10 '20 at 13:30
  • What are you using to generate the HTML? – cbr Mar 10 '20 at 13:31
  • i'm using EJS, so that i can manipulate it better with JS :) – rmbrandao Mar 10 '20 at 13:35
  • You could pass a helper function to your EJS views which generates the links. You'd define this function in the controller/router and that is the function that adds the prefix to the links. See [_Nodejs EJS helper functions?_](https://stackoverflow.com/a/18501016/996081). – cbr Mar 10 '20 at 13:38
  • I'll take a look on that, I think it's what I need, thank @cubrr – rmbrandao Mar 10 '20 at 13:42

0 Answers0