To add optional splat param with Node Express.js routing, we use a question mark.
For instance, we write
router.get("/path/:id*?", (req, res, next) => {
res.render("page", { title: req.params.id });
});
to call get
to with the path of the route.
We make id
an option parameter with ?
.
And we get the id
value with req.params.id
.