Router mergerParams setting on app initialization

Open
#5,006 3 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Domain
api, backend

Research direction

Start with the two linked application.js sections around the strict and caseSensitive settings, then trace how the child app is mounted with root.use('/path/:someParam', app). Confirm how router initialization handles those settings and how req.params behaves in the provided example. Done means the mergeParams behavior is configurable at app initialization and the example exposes the parent path parameter without regressing existing settings.

Written by the indexing model from the issue text.

Description

pr

Hi,

is there way to make app merge params from the parent app right now? As far as I can tell only the strict and caseSensitive settings are configurable:
https://github.com/expressjs/express/blob/33e8dc303af9277f8a7e4f46abfdcb5e72f6797b/lib/application.js#L144-L149
https://github.com/expressjs/express/blob/318fd4b543ffbebf97bf0b6c49188afae45741f5/lib/application.js#L64-L75

My use case is that I have the root app and child apps for view rendering, because I am able to limit the views available to the app, which makes code a bit shorter and cleaner and also project structure is nicer. However I don't have the access to the path parameters in this case.

const root = express()
const app = express()
app .set('views', 'path1')
app .get('/', (req) => console.log(req.params)) // prints '{}'

root.use('/path/:someParam', app)

I can submit a PR as it is only one line of code if I didn't overlook something.

Dominant language
JavaScript
Stars
69.7k
Forks
25.6k
Avg merge
2d 9h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from expressjs/express

All issues in expressjs/express

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.