[Feature Request] Support url parameters without router positions
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
It’s only possible to use parameters if they’re route parameters.
For example, to access name and age, a route must be set up as:
:name/:age
Expected behavior
It should be possible to use url parameters as well:
E.g. http://localhost:3000/cats?name=gary&age=1.57
Minimal reproduction of the problem with instructions
@Get('cats')
async getByNameAndAge(@Param('name') name: string, @Param('age'): number): Promise<object> {
return Promise.resolve({"name": name, "age": age, "success": true})
}
What is the motivation / use case for changing the behavior?
Url parameters being parsed in any order is better for long lists of parameters and the potential for optional parameters compared to positional route parameters.
Environment
Nest version: 4.6.6
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Get current route without parameters - Stack Overflow
To get current route without query parameters, you can use below mentioned single line: this.router.url.split('?')[0].
Read more >Using parameters in routes - Drupal Wiki
Parameters can be used to pass dynamic values from the URI to the controller.
Read more >How to Get URL Parameters with JavaScript - SitePoint
Learn how to parse query string parameters and get their values in JavaScript. Use the results for tracking referrals, autocomplete, ...
Read more >Routing and URL Parameters | Routing and Navigation | Flow
A navigation target that supports typed parameters passed through the URL should: Implement the HasUrlParameter interface, and. Define the parameter type ...
Read more >URLSearchParams - Web APIs - MDN Web Docs
Chrome Edge
URLSearchParams Full support. Chrome49. Toggle history Full support. Edge...
@@iterator Full support. Chrome49. Toggle history Full support. Edge...
URLSearchParams() constructor Full support. Chrome49. Toggle...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll provide an example in the docs.
@natejgardner you can use
@Query('name')
or@Query('age')
as well.