Sometimes, we want to configure dynamic routes with Express.js and JavaScript.
In this article, we’ll look at how to configure dynamic routes with Express.js and JavaScript.
How to configure dynamic routes with Express.js and JavaScript?
To configure dynamic routes with Express.js and JavaScript, we can make a route accept URL parameters.
For instance, we write
app.get("/article/:id", (req, res) => {
res.render("article" + req.params.id);
});
to add the /article/:id
route.
:id
is the placeholder for the id
route parameter.
And we get the value of that from req.params.id
.
Conclusion
To configure dynamic routes with Express.js and JavaScript, we can make a route accept URL parameters.