Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Interface

RouterOptions

RouterOptions is the optional configuration object for express.Router(). It controls case sensitivity, parent-parameter inheritance, and strict trailing-slash matching; each option defaults to false.

Since
v4.5.0+ for mergeParams

How it works

RouterOptions is the optional object accepted by express.Router([options]). Its three documented settings control URL case matching, inheritance of parent route parameters, and treatment of trailing slashes; omitted settings default to false.

Syntax

express.Router([options])

Parameters

NameTypeDescription
optionsObject | undefinedOptional configuration object for router behavior; omitted properties default to false.
options.caseSensitiveBooleanEnables case-sensitive matching; default false.
options.mergeParamsBooleanPreserves parent-router req.params; default false.
options.strictBooleanEnables strict routing for trailing slashes; default false.

Returns

Router — a router object to which middleware and HTTP method routes can be added.

Key points

  • RouterOptions is an optional object used to configure the behavior of a router created by express.Router.
  • caseSensitive makes route matching distinguish uppercase and lowercase characters.
  • strict makes the router treat a path with a trailing slash differently from the same path without one.
  • mergeParams carries route parameters from the parent router into the child router.

Common mistakes

  • With mergeParams enabled, a child parameter with the same name as a parent parameter overrides the inherited value.
  • strict is false by default, so paths differing only by a trailing slash normally match identically.

Example: Configuring an Express router

const express = require('express');
const router = express.Router({
  caseSensitive: true,
  mergeParams: true,
  strict: true
});

router.get('/users/:id', (req, res) => {
  res.json({ parentId: req.params.parentId, id: req.params.id });
});

const app = express();
app.use('/teams/:parentId', router);
app.listen(3000);

Creates a router that distinguishes URL case and trailing slashes while retaining parameters inherited from its mounted parent route.

When to use it

Nested resource routes

A mounted child router must read an identifier captured by its parent path.

Case-sensitive endpoints

An API requires URLs whose capitalization carries meaning.

Strict URL conventions

An application must distinguish canonical paths with and without trailing slashes.

Interview questions

QWhat is RouterOptions and what does it configure?

RouterOptions is the optional configuration object passed to express.Router. It supports caseSensitive, mergeParams, and strict, and the router is returned for adding middleware and routes.

Follow-up: How would a mounted router access a parameter from its parent path? Pass mergeParams: true when constructing the router; otherwise the parent parameter is not preserved.

QWhat does caseSensitive do?

caseSensitive enables case-sensitive path matching. Its default is false, so paths such as /Foo and /foo are treated as equivalent.

Follow-up: What effect does strict have instead? It controls trailing-slash matching, making /foo and /foo/ distinct when enabled.

QWhat does mergeParams change?

mergeParams preserves req.params values from the parent router when a child router is mounted. If names conflict, the child parameter takes precedence.

Follow-up: When is this useful? It is useful for nested routes whose handlers need an identifier captured by the mounting path.

  • express.Router()
  • Router
  • req.params
  • router.use()
  • router.get()

Source: Router - Express.js. Checked 2026-10-15.