question: How to get route.param on a RoutingController?
See original GitHub issueI was trying to…
I have a very specific scenario giving the following situation where I need to check on all my routes if a param resourceType
exists or not add some params to the request
object giving my param value:
app.param('resourceType', (req, res, next, resourceType) => {
try {
const {
getResource,
getResources,
getUsers,
getRoles,
updateRole,
deleteRole,
createSuperAdmin,
deleteSuperAdmin,
} = getResourceRoutersParams(resourceType);
req.resource = {
getResource,
getResources,
getUsers,
getRoles,
updateRole,
deleteRole,
createSuperAdmin,
deleteSuperAdmin,
};
next();
} catch (e) {
logger.error(e);
throw new ResourceNotFoundError();
}
})
I’m solving the issue using the app.param
API
The problem:
All my routes contain a :resourceType
param:
- GET
/resources/:resourceType/:resourceId/users
- GET
/resources/:resourceType/roles
- GET/PUT/DELETE
/users/:userId/:resourceType
- GET/PUT/DELETE
/users/:userId/:resourceType/:resourceId
There is any way to implement it other than adding a middleware for each route?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to pass routing parameter to controller constructor
Why does it have to actually be passed into the constructor? As a route value, you can already access it any time via:...
Read more >Accessing named parameter in custom route from within a ...
This works fine but how can I access that <order> named parameter within my controller? Is the only way to use craft::$app->request->getSegment( ...
Read more >Everything You Should Know About ASP .NET Core Routing
There are some route parameters which are identified by framework, e.g. controller , or action are most common templates that you can find...
Read more >Express Tutorial Part 4: Routes and controllers - MDN Web Docs
Route parameters are named URL segments used to capture values at specific positions in the URL. The named segments are prefixed with a...
Read more >Dynamic Routing with Route Parameters - Adocasts
Here, we've named our route parameter id to signify that the route parameter is meant to be a post id value. So regardless...
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
Ah ok. That makes sense. Sorry for the wrong answer 🤦🏾 If you find a more elegant solution I would be curious as to what you do.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.