-
-
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
Question: Is there a way to identify a route and create href link to it? #2739
Comments
Come on guys, what's up, not even a single comment? No one reading those issues? |
Hi! Yes, currently it's not possible, especially when you start to think about how we actually allow your middleware to alter I believe, though, there are third party modules (I think part of kraken?) than provide this functionality, though. |
Thanks for the answer, @dougwilson ! I've just seen their enrouten package. It does some pretty magical stuff that I'll have to deeply investigate tomorrow and see if I can use. Thanks for that! Otherwise - is it really that bad idea to check if one of the params passed to the router is |
+1 to this, will allow nested routes a breeze too. Currently I'm doing the following, which is not the most pretty thing out there but it works :) (I tested several reverse packages too and didn't liked the results): global.erp.app.set('route:organizations', global.erp.app
.route(global.erp.config.get('api:prefix') + '/organizations')
.get(require('./routes/index'))
.post(require('./routes/create'))); |
I created a PR for support for named routes in the Router project if anyone from this issue wants to comment - pillarjs/router#36 |
Is there still no way to generate urls to routes instead of hardcoding paths all over the place? |
Hi @edevil, I think you should go read the conversation on that PR linked by @sjanuary. I have not seen any finalizing progress on it, so if you can re-ignite the conversation in a productive way that would be great! If I can give some feedback, I think your approach here could use some refining. It is usually better to only comment when you have something constructive to add to the conversation, so a better way to phrase the sentiment maybe would be "Is there anything I can do to help get this feature?". That way we as the maintainers would be very willing to help point you in the right direction, as I did above. Happy contributing! |
@wesleytodd I didn't mean to sound dismissive. Since I am new to the Node ecosystem and this was an open ticket with more than 2 years without activity, I really thought that there was something more and it had simply been forgotten. Regarding pillarjs/router#36, it also seems stalled, depending on pillarjs/router#29 which is also stalled. Is this the router that express uses underneath? |
Hey, I understand it looking forgotten. It takes someone championing the topic to push things forward, sometimes pinging on a topic for a while to get people's attention. Yes pillarjs router is the express router, but for the next major release we are working on. This would be a great feature to get landed before then, so maybe you can start some conversations over there on how you think we can move it forward. |
Hi there,
I'm using Express for what I imagine to be a large project, and I have many href links inside my views. I do not want to hardcode them at all! Any time I change something I must go and search in the code in order to make it work.
Short story: how can I track back a route, so I can use this in views:
Long one: I've searched for a day about routing in Express and I found a few "reverse" routing packages, ALL of them quite broken - they either don't work with
Router()
or they create new Router every time, etc.I got to know all the Layers and stacks that the Routing part creates. I understand that you guys want order in routes, as well as multiple handlers for the same path. I agree with all that.
But isn't there some easy way to add ids for those routes? I found that if I simply use
I get
namedFunction
as a name of the Layer in the stack, which is great. But if I use router (likerouter.route('/path').get(...).post(...)
, then the Layer is namedrouter
and inner stack containsanonymous
functions.My idea here was that after I add all routes, I can browse
app._router
and it's stacks, getting names of routes, then using a function with name parameter so I can construct back a route.Am I missing something, or there is no way to make this easy working? I can't imagine someone having 100+ routes in a project, that hardcodes their links inside it - I just refuse to think of it :)
The text was updated successfully, but these errors were encountered: