I'm trying to make the multiple URLs work on a single express route. How can I make the following URLs all route to the same page?
It seems like this should work but it's not:
router.get("/:slug?(/amp)?", function(req, res, next) {
  if (!req.params.slug) {
    req.params.slug = 'home'
  }
  getData(slug, function(err, data){
    res.render('index', data)
  });
});
                You can have it in single express route by placing multiple URLS inside an array. In your case, this will be
  app.get(['/', '/:slug', '/amp', '/:slug/amp'], function(req, res, next) {
    if (!req.params.slug)
      req.params.slug = 'home'
    getData(slug, function(err, data){
      res.render('index', data)
    });
  );
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With