-
Notifications
You must be signed in to change notification settings - Fork 12
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
how to add the functionality to express.Router() #13
Comments
Just to clarify, you are working with express.Router but not an express app? How does the above code fail? |
so this is my use case:
So here i need to add PS: I figured out there is no need to call registerAppHelpers on the searchRouter. |
That behaviour is intended and correct. When you create instances of express.Router, those instances are designed to be isolated and not supposed to know where they are used (in this case, inside of server.use('/search', searchRouter);
server.use('/preciseSearch', searchRouter); If you then called build on |
okay thank you |
I feel like it would be nice to have first class support for this... would there be any way to hook into Could there be a method on the request with the context of where the current Router is mounted...? I don't know... just trying to wrap my head around this one. Seems like a shame that if you want to use Routers to isolate parts of an app that you have to go back to manually constructing URLs... var express = require('express');
var app = express();
var Router = require('named-routes');
var router = new Router();
router.extendExpress(app);
router.registerAppHelpers(app);
app.get('/admin/user/:id', 'admin.user.edit', function(req, res, next){
var url = req.namedRoutes.build('admin.user.edit', {id: 2}); // => /admin/user/2
});
var searchRouter = express.Router();
router.extendExpress(searchRouter);
searchRouter.post('/users', 'users', function(req) {
var url = req.namedRoutes.build('users'); // => /search/users
});
app.use('/search', searchRouter);
app.listen(3000);
|
How can i add this functionality to express.Router() ?
this will not work even with removing the router.extendExpress and router.registerAppHelpers
var searchRouter = express.Router(); router.extendExpress(searchRouter); router.registerAppHelpers(searchRouter); searchRouter.post('something', 'something'
The text was updated successfully, but these errors were encountered: