Back to Expressjs

Routing Args

_includes/api/en/5x/routing-args.html

latest1.1 KB
Original Source

Arguments

ArgumentDescriptionDefault
pathThe path for which the middleware function is invoked. It can be any of the following:
  • A string representing a path.
  • A path pattern.
  • A regular expression pattern to match paths.
  • An array containing any combination of the above.

For examples, see Path examples. | '/' (root path) | | callback | One or more callback functions. Accepted formats:

  • A single middleware function.
  • Multiple middleware functions separated by commas.
  • An array of middleware functions.
  • A combination of the above.

You may provide multiple callbacks that behave like middleware. These can call next('route') to skip remaining callbacks for the current route. This is useful for conditional routing logic.

If a callback throws an error or returns a rejected promise, next(err) is invoked automatically.

Since both router and app implement the middleware interface, they can also be used as callback middleware.

For examples, see Middleware callback function examples.

| None |