-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] resourcesRoutes list is sensitive to ordering #2910
Comments
I don't see how that can be possible. On which URL?
Which props are you thinking about? Also, one I suspect you have a very custom use case, in which case I advise implementing your own |
The router tries to match your routes in the order they are defined, this is how react-router work. remix-run/react-router#1677 (comment)
If we allow
I think it should:
All of these path can be extended, for instance, these are valid and may cause conflict on ordering:
The
Unfortunately, this is the most simple case we can have. People must order their route by priority. Another possibility to solve this would be to add the |
I don't understand how an URL like |
You are right, I was pasting the wrong code part. I just updated it with the right one. I have prepared examples to demonstrate the issue and possible fix:
<Route path="/roster" component={Roster} />
<Route path="/roster/schedule" component={Schedule} /> Result:
<Route path="/roster/schedule" component={Schedule} />
<Route path="/roster" component={Roster} /> Result:
<Route path="/roster" component={Roster} exact />
<Route path="/roster/schedule" component={Schedule} /> Result:
This is also a valid action and should be considered. Currently (2) is the one action people can do but... setting order on a high amout of In our case, (2) will certainly bring route conflict issues because we group Without
(3) and (4) together are imoo the prefered action as they give the more flexibility and the best default configuration. We fixed with sorting. |
I'm wondering why we don't use |
@kopax thanks for the detailed description. There is indeed a bug. |
Thanks do you want me to fix this? What action do you prefer? |
Let's wait for @djhi's feedback before deciding on a fix. |
@djhi any though about this one? |
Sorry, missed this one. I'm ok for using |
I was hitting this more and more while adding resources. Can we add this to next release? Thanks. |
@fzaninotto @djhi, I have found that I suggest the following implementation:
Regarding (4), because they are all tightly coupled to the URL, it is not dirty to apply a route props on them. This would only work on If you do not want a Doing this will have more benefits than simply adding
The issue is specific to react-router and it is not a bug, it's the configuration part. We can't do much about it, a warning should be added to the documentation when using If you agree with or without (2), I can implement it. |
Hey, I have a similar issue. My resource route: <Resource
name={"user-management/users"}
list={UserList}
edit={UserEdit}
create={UserCreate}
show={UserShow}
/> My custom route: <Route path={"/:resource/:id/authorities"} component={AuthoritiesEdit} /> The route couldn't render. We use the The quickest fix i found was the following: - <Route path={"/:resource/:id/authorities"} component={AuthoritiesEdit} />
+ <Route path={"/authorities/:resource/:id"} component={AuthoritiesEdit} /> Could we please support |
We need to give back the control to the end user, could we please have an update on this issue? I'll gladly help to implement the next specification to see it release soon. As a reminder, tabs needs |
I'm not fond of any of the solutions you've suggested:
Also, using resource names that are actually paths is mixing responsibilities between the frontend and the backend. In react-admin's design, it's the data provider's responsibility to translate a resource name into an API URL. This makes me think that the problem you're having in the first place it due to a wrong usage of react-admin. So I maintain my initial reaction: your use case isn't supported by react-admin, and you should write your own I'll close this issue and the related PR. Thank you anyway for helping us understand the problem. |
That could definitely be done in the If we want to have similar links between the two, 99% of the code is working. react-router give use the grain to configure route, tabbed route, anything. The current interface of Resource doesn't give us the grain to configure the route entirely, and this limitation comes from react-admin. I offered one more solution that you have not listed. It is quite good and it's the one we have chosen. Using sorting (by PATH desc) won't have any effect on the current strategy for all use cases. I recommend using that one.
Since this is not blocking us as this can be solved userland with an ugly hack, it's not dramatic if it's not integrated but that should be also considered as a final choice in your listing. |
We have the following
resourcesRoutes
:This fail to generate a working
<Route />
, becauseproject-management/projects/services
will catch beforeproject-management/projects
.Instead we must order it DESC :
This will make a valid
<Route />
.It can also be solved using
exact
props, andcustomRoutes
, but this is too sensitive for being an expected behaviour, and it is not specified anywhere in the documentation.If you agree, this ticket consists of taking all the user props from
<Resource />
and pass them to the<Route />
component.https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/Resource.tsx#L80
The text was updated successfully, but these errors were encountered: