node.js - Make dynamic path in node and express js -


i trying make route dynamic /review-{title}-{id} , causing error don't know why, if user enter wrong params how handle that. client requirement above, not in node , express please suggested how make routes above. if needed make route /review/:title/:id format how can make that.

i trying redirect me out 404 page,

please find existing code details inside, server.js

this working..  app.get('/review', (req, res) => {  res.sendfile(path.resolve(__dirname, '../client/review.html')); });  not one.. app.get('/review-*-*', (req, res) => {  res.sendfile(path.resolve(__dirname, '../client/review.html')); });  not 1 working app.get('/review/*/*', (req, res) => {  res.sendfile(path.resolve(__dirname, '../client/review.html')); });  404 page call evrytime while accessing dynamic pages app.get('/*', (req, res) => {  res.sendfile(path.resolve(__dirname, '../client/404.html')); }); 

check out syntax routes in express.

in cases you're better off using route params, e.g.:

app.get('/review/:title/:id', (req, res) => {  res.sendfile(path.resolve(__dirname, '../client/review.html')); }); 

some more flexibility (but more opaque developers) match on regex.

i think can put * in middle of words (they give example '/abc*def', i'm not sure how nicely plays other things you're doing, , don't think can have multiple *'s in pattern if that.)


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -