-
-
Notifications
You must be signed in to change notification settings - Fork 16.8k
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
Add "set" Method to "Router" #2524
Comments
I found that one way to solve my special Layout problem is adminRouter.use(function(req, res, next)
{
res.locals.layout = "adminMain";
next();
}); |
The solution from yesterday is no real solution. Consider the following example var adminRouter = express.Router();
adminRouter.use(function(req, res, next)
{
res.locals.layout = "adminMain";
next();
});
adminRouter.get("/", admin.admin);
app.use("/admin", adminRouter);
app.get("/register", register.register); When I first visit the |
This needs discussion, but from me I am (currently) -1, because that's what the difference is between an app and a router: an app has settings. |
In case you need different settings, you should go with a sub-app pattern and in your main express app, actually use it. firstExpressapp.use('/admin/', anotherExpressApp); @dougwilson is there any performance impact when using sub-apps instead of nested Router? I think there shouldn't be as app delegates all the requests to the top-level router anyway. |
Well from scoping perspective... in version 3 this was great, because there was no Router, with addition to router, app -> router -> response; router should/could get a locals attribute that would upgrade locals to the response object and possible views that would use them. You can do this manually as @akesser pointed out. |
Also with @dougwilson on this -- the functionality is probably better suited in it's own sub-module somehow. |
Hey guys,
I think it would be nice to be able to set options to single Routes. For example one can set a default layout for the handlebars rendering engine with
or with
When using a
express.Router()
for example withapp.use("/admin", adminRouter)
it would be nice to be able to use something liketo prevent using
for every call to
res.render
Thanks
-André-
The text was updated successfully, but these errors were encountered: