-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Named routes #3743
Comments
Interesting feature! I'm taking a look at the source and i have already done the decorator part, seems really good! |
This quite the same as in Django: https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#url It also allows injecting parameters to the URL. Would be very helpful in MVC projects with templates to be rendered. |
A little surprised this feature doesn't exist, since it's fairly standard with other frameworks. |
Sails.js has getUrlFor. This enhancement is a great idea. Looking forward to seeing it get merged. 👍 |
I like this idea. However, I don't think that we should use |
PRs are more than welcome :) |
Add @WithAlias decorator which allows arbitrary aliases to be attached to Controller methods and later retrieved in views and resolved to full route path. Resolves nestjs#3743
Add @WithAlias decorator which allows arbitrary aliases to be attached to Controller methods and later retrieved in views and resolved to full route path. Resolves nestjs#3743
Add @WithAlias decorator which allows arbitrary aliases to be attached to Controller methods and later retrieved in views and resolved to full route path. Resolves nestjs#3743
@kamilmysliwiec , I've raised PR #5117 to add a Looking for some feedback on the implementation as well as the method name exposed to views (currently Follows @getspooky 's idea, but uses (It's my first contribution to nest, so fully expecting feedback to address ... great framework 💯 ) |
Here's my use case: I want to disallow all requests except for a few API endpoints. @sjones6 |
Let's track this here nestjs/docs.nestjs.com#1400 |
This can also help in avoiding repetition in url writing in e2e tests. instead of rewriting the whole url, we can simply refer to named routed and passing necessary parameters. |
nestjs/docs.nestjs.com#1400 seems to maybe have stalled? Did this feature make it in through any other PRs by any chance |
Look here, I made a Draft PR: #10178 |
This would be a great feature! I miss it |
Feature Request
Is your feature request related to a problem? Please describe.
So, the problem it self comes when you're build a view, paths can change,you can switch global prefix, or whatever but router name, will be static, stick to the dynamic path.
Describe the solution you'd like
So I would like to have a possibility to set a name to the route that I can use it in view.
Teachability, Documentation, Adoption, Migration Strategy
I general, there are 2 packages, that some1 might think they cover the problem, first one is: https://www.npmjs.com/package/named-routes which do what it should do, but only on the Router scope, which is useless in our case, because each of the controller have his own isolated router, so you don't know the full path, second one is https://www.npmjs.com/package/express-reverse which seems to do the full funny staff for us, but idk if if it's not working the same way as the previous one.
So right now that we have:
I would like to propose to add a second optional parameter to
METHOD
decoratorsthat might looks like:
and then in view, you will be able to use kind of function to get back the full url, fe:
Where
url
function|helper might live inexpress.local
if we're talking about express or in different location, regarding to adapter.What is the motivation / use case for changing the behavior?
Problem here lives between a developer and web designer co we can call it PEKBAC in general, but I would like to solve it in different approach, kind of contracts approach, like when a developer who wrote a whole business logic make a deal with a web developer who build a views, that routes will be named in some way, web developer doesn't have to think about prefiex, or care about developer changes in paths. Even if you have in plenty places link to specific view, and you change its path, but you're using name path, until it won't change, you're safe.
Regards.
UPDATE
I have update a decorator proposition to handle it as well as with literal object notation, because maybe in future some1 might get other proposition, so this will allow to extend this variation.
The text was updated successfully, but these errors were encountered: