Custom path for resource route in react-admin
Asked Answered
V

1

6

Is there any way to specify custom paths for resources?

Example: <Resource name="User" path="/manageUsers" {...}>

If it's not possible "per resource", can we for example have all the CRUD pages be under a same basepath like: /crud/{/$resource.name} but keep the custom routes without that basepath.

Thank you very much.

EDIT #1

For context, we are building an admin panel that will have a lot of flows, basically step-by-step creation of resources. So I applaud the react-admin library for what it does (manage the CRUD part), but I want more flexibility in how the URLs are going to be.

I will need to have a section called /manageUsers/ that will have some data like a dashboard, and then the list could be /manageUsers/list/.

And then I may need another section called /customers/ that would list directly on that page.

EDIT #2

To give another use case, I'm trying to use graphQL as the dataProvider, and I had to rename all my resources since the rest API is using users where as the graphQL resource is User. So all my urls are now different!

I hope that makes it a bit more clear.

Vitiligo answered 8/2, 2019 at 3:29 Comment(3)
Can you explain the issue with the current implementation ? What are you trying to achieve ?Hygrometer
@GildasGarcia, please see my edit, and thanks for trying to help me :)Vitiligo
@GildasGarcia, any chance you could help me after my last edit?Vitiligo
H
4

Is there any way to specify custom paths for resources?

No, this is not supported at the moment. One way to tackle this would be to use manageUsers as the resource name and translate it to User in your dataProvider.

I will need to have a section called /manageUsers/ that will have some data like a dashboard, and then the list could be /manageUsers/list/.

Definitely not supported by default either. However, you can replace the default Resource component with your own. It actually just creates routes for the resource inside a React Router switch. Note that you'll probably have to override the redirect prop of some components (such as Edit) because, when passed list, they expect the list to be at the resource root path.

I had to rename all my resources since the rest API is using users where as the graphQL resource is User

That's the dataProvider job to translate resources names into what your backend expect. Use resource names that make sense for your users (url wise).

Hygrometer answered 22/2, 2019 at 6:45 Comment(2)
Thank you very much for this detailed answer. I actually ended up trying to use manageUsers/customers as the resource name and writing a function to map those "url-like" resource names to GraphQL names using a custom buildQuery. Can you confirm if I can use a slash in the resource name? Everything seemed to work as intended, but you may have more insight for me. Thank you so much.Vitiligo
I don't recall anything that would prevent it from workingHygrometer

© 2022 - 2024 — McMap. All rights reserved.