0

Right now I have two routes, invoking the same method.

Let's say the method's name is myMethod And two routes are / and /:params

router.get("/", myMethod);
router.get("/:param", myMethod);

Since in both cases I have to invoke the same method, I want to use a single route to invoke the myMethod. Something like this,

router.get('/' or '/:param', methodName);

If it is possible, then how can I do this?

Shams Nahid
  • 6,239
  • 8
  • 28
  • 39

1 Answers1

5

You can use an array :

router.get(['/', '/:param'], myMethod);
ElJackiste
  • 4,011
  • 5
  • 23
  • 36