sanair96
sanair96

Reputation: 39

How do we make part of the route optional in Expressjs?

How do I make a part of the route(not just parameters) as optional? For example in:

\pid\:pid\did\:did

If did is not present :did should not be present.

How do I go about writing a route for this?

Upvotes: 0

Views: 39

Answers (1)

Jeba
Jeba

Reputation: 858

As per your requirement, you have to create two end point.

  1. /pid/:pid
  2. /pid/:pid/did/:did

This will solve your problem.

Upvotes: 1

Related Questions