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
Post a Comment