Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router mergerParams setting on app initialization #5006

Open
blazmrak opened this issue Oct 2, 2022 · 3 comments
Open

Router mergerParams setting on app initialization #5006

blazmrak opened this issue Oct 2, 2022 · 3 comments
Labels

Comments

@blazmrak
Copy link

blazmrak commented Oct 2, 2022

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:

express/lib/application.js

Lines 144 to 149 in 33e8dc3

app.lazyrouter = function lazyrouter() {
if (!this._router) {
this._router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});

Object.defineProperty(this, 'router', {
configurable: true,
enumerable: true,
get: function getrouter() {
if (router === null) {
router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});
}
return router;

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.

@dougwilson
Copy link
Contributor

Hello, thank you for your issue. You are right, there is no option for mergeParams for an app, only routers. I don't see any reason off-hand that an app cannot also enable that setting. If you would like to make a PR, you're welcome to do so, just remember to add all the necessary tests around the feature, not just one line to the one file :) . If you're not comfortable doing that, we can still add it for you, just let us know.

@blazmrak
Copy link
Author

blazmrak commented Oct 2, 2022

I'll take a stab at it. By the way, how are different branches handled? Do I submit PR for both master and 5.0, or just 5.0?

@dougwilson
Copy link
Contributor

I believe this is just adding a feature (in the form of a new option), so if that is the case just master is all you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants