sensitive-blue
sensitive-blue8mo ago

How to get the resources definitions from the server(runtime resources)?

I am implementing a protocol-driven CMS client based on refine, but I find nothing in the refine documentation about how to dynamically set resources.
3 Replies
kapa.ai
kapa.ai8mo ago
Hi @zybzzc. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The extracts provided do not contain information about dynamically setting resources from the server in refine. However, you can define your resources and their routes in the <Refine /> component as shown in the extracts. Here is an example:
<Refine
resources={[
{
name: "products",
list: "/my-products", // <http://localhost:3000/my-products>
show: "my-products/:id", // <http://localhost:3000/my-products/1>
create: "/my-products/new", // <http://localhost:3000/my-products/new>
edit: "/my-products/:id/edit", // <http://localhost:3000/my-products/1/edit>
clone: "/my-products/:id/clone", // <http://localhost:3000/my-products/1/clone>
},
]}
/>
<Refine
resources={[
{
name: "products",
list: "/my-products", // <http://localhost:3000/my-products>
show: "my-products/:id", // <http://localhost:3000/my-products/1>
create: "/my-products/new", // <http://localhost:3000/my-products/new>
edit: "/my-products/:id/edit", // <http://localhost:3000/my-products/1/edit>
clone: "/my-products/:id/clone", // <http://localhost:3000/my-products/1/clone>
},
]}
/>
(Source: refine.dev/docs (https://refine.dev/docs/guides-concepts/routing/#relationship-between-resources-and-routes-)) For more detailed information, I recommend checking the official refine documentation or reaching out to the refine community for support. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8mo ago
<@260795556333355009> kapa.ai is still learning and improving, please let us know how it did by reacting below
unwilling-turquoise
unwilling-turquoise8mo ago
Hey @zybzzc, this is one of the most requested features from Refine to have it built in. We're discussing some of our options to implement it in the core. If you have any ideas to share, please open an issue on github as a feature request and we can discuss it further 🙏 For the current structure, it can be done by making requests to the API for the resources right above the <Refine /> component and passing the resources prop by your API responses. This can be done by using a context or just handling the calls in the component you're defining the <Refine /> component. Until we implement this feature and release it I think it will be a good thing to add this as an example in our documentation to help users. Writing it down to our to-do 🚀