Multiple params in query
How can I use multiple params in a route?
Something like /user/:uid/object/:id ?
it seems that only "id" is a valid property for ParseResponse for
const parse = useParse()
const params = parse()
4 Replies
Hi @simoneb. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, you can use multiple parameters in a route with Refine. Refine supports route parameters defined with
:param
syntax. You can use these parameters in your action definitions and create your routes accordingly.
For example, if you have a user
resource and you want to create a route for the show
action of a specific user's object, you can define the show
action as /user/:uid/object/:id
and use the uid
and id
parameters in your component.
Here is an example of how you can define it in your resources:
Then, you can use the useParsed
hook to access these parameters:
In this example, useParsed
hook leverages the parse
method of the routerProvider
to access the URL and query parameters along with the inferred resource
, action
and id
from the URL. The params
object contains both the URL parameters and the query parameters[^1^][^2^].
[^1^]: (https://refine.dev/docs/routing/hooks/use-parsed/)
[^2^]: (https://refine.dev/docs/routing/router-provider/#parse)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@539513465103056900> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
vicious-goldOP•2mo ago
is it possible to define custom resources actions?
e.g. I want
path /admin/object/:id/edit
or
/user/:uid/object/:id/edit
depending on the user role.
if I try to add a custom action like
resources={[
{
name: "user",
list: "/user",
show: "/user/:uid/object/:id",
edit: "/user/:uid/object/:id/edit",
admin_edit: "/admin/object/:id/edit", create: "/user/create",
}
]} I get a "Object literal may only specify known properties, and 'admin_edit' does not exist in type 'ResourceProps'". error @kapa.ai
{
name: "user",
list: "/user",
show: "/user/:uid/object/:id",
edit: "/user/:uid/object/:id/edit",
admin_edit: "/admin/object/:id/edit", create: "/user/create",
}
]} I get a "Object literal may only specify known properties, and 'admin_edit' does not exist in type 'ResourceProps'". error @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
Sorry @simoneb, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?