rare-sapphire
rare-sapphire4mo ago

Different set of resource based on path

Hi, is it possible to have a different set of resource based on the first segment of the path? e.g. for /path1/... I want the resources to be [ { name: 'a1', ... }, { name: 'a2', ... }, ] but for /path2/... I want the resources to be [ { name: 'b1', ... }, { name: 'b2', ... }, ]
2 Replies
kapa.ai
kapa.ai4mo ago
Hi @yw. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Refine's resource definitions are specified inside the resources object, which is passed to the resources prop of the <Refine /> component. These resource definitions, in combination with route definitions, set up a Refine app's nav menu items, their navigation URLs, as well as breadcrumbs, and help infer the default resource name of a CRUD page along a route [source (https://refine.dev/blog/daisy-ui-react-admin-panel#resource-definitions)]. However, based on the provided knowledge sources, there is no direct way to dynamically change the entire set of resources based on the first segment of the path. The resources prop in Refine is typically defined statically when the <Refine /> component is initialized. That said, you can define nested routes within a resource. For example, if you want to make a request of the URL /user/1/posts, you can do so with the resource property on all data hooks [source (https://refine.dev/docs/guides-concepts/faq#how-can-i-request-an-api-with-nested-route)].
import { useTable, useOne } from "@refinedev/core";

useTable({
resource: "/users/1/posts",
});
import { useTable, useOne } from "@refinedev/core";

useTable({
resource: "/users/1/posts",
});
If you need more complex routing or resource configuration, you might need to extend or customize Refine's built-in components or hooks. For instance, there was a feature request to add an option to hide a resource in the menu, which would require customizing the <Sider /> component or the useMenu hook [source (https://github.com/refinedev/refine/issues/2388)]. For more specific guidance or feature requests, you might want to reach out to the Refine community or check the official documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@1161319523077603359> kapa.ai is still learning and improving, please let us know how it did by reacting below