-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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]: Regression of useResolvedPath
in 6.19.0
#11048
Comments
useResolvedPath
in 6.19useResolvedPath
in 6.19.0
I think this might be related to the bugfix in #10983. @brophdawg11 @mjackson I am not sure if the behaviour that I am seeing above is now actually intended behaviour or an unintended side effect of the bugfix. |
This is the intended behavior - what you're showing here was the previous buggy behavior that in splat routes, |
@brophdawg11 Thank you for the explanation 👍 How would I be able to get the original result? Your link suggests that I could use To clarify, my use case is an "active route" detection very similar to what This is basically what I have: function Container() {
return (
<>
<CustomLink path="dolor" />
<CustomLink path="amet" />
</>
);
}
function Dolor(props: { path: string }) {
const navigate = useNavigate();
const path = useResolvedPath(props.path);
const match = useMatch(path.pathname);
const active = match !== null;
const handleClick = () => {
navigate(props.path);
};
return (
<span data-active={active} onClick={handleClick}>{…}</span>
);
} Previously, both instances of
With the recent change to |
I have the same problem. Now I am unable to deal with navigate inside '/path/to/*' route ... eg:
const to = useResolvedPath('path/to');
const handle = () => navigate(to); // it will navigate to /base/path/to in any situation.
const to = useResolvedPath('path/to');
const handle = () => navigate(to); // it will navigate /base/path/to/path/to/path/to/... depends on my current path. |
This is based on how you've set up the route hierarchy. In the linked example, the splat is a level all by itself, which makes it easier to drop just the splat portion by going up one level. You have a static portion and a splat potion in your setup which means So you could change from Otherwise I would leverage
Try this on 6.20.0 - we found a few additional codepaths that needed the same update we made for |
Please reopen this issue. I understand that the previous behavior was buggy, but if fixing that bug breaks existing apps, that's a breaking change, and it shouldn't be published in a minor release. According to semver, the fix for We built react-admin, which powers at least 20,000 live applications, on top of the previous version. Our code included a fix for the useResolvedPath problem. Your "fix" that landed in 6.19 breaks all these apps (cf #11053). Worse: it's impossible to publish a fix in react-admin that works in all versions of react-router. |
What version of React Router are you using?
6.19.0
Steps to Reproduce
Use
useResolvedPath()
with relative path inside double-nested<Route/>
.See https://github.com/sgoll/react-router-test for a full reproduction with more details.
Expected Behavior
useResolvedPath()
should return the same path as in 6.18.0 and be independent of nested routes.Actual Behavior
When nested in routes within routes (double-nesting),
useResolvedPath()
returns one level more than expected; this is different from before (6.18.0) and different from the top-level behaviour.The behaviour is also not consistent when adjusting to explicit relative paths like
./dolor
or../dolor
. The first doesn't seem to change anything, and the second strips away two levels simultaneously.Screenshots
useResolvedPath("dolor") -> {"pathname":"/ipsum/dolor",…}
useResolvedPath("dolor") -> {"pathname":"/ipsum/dolor/dolor",…}
The text was updated successfully, but these errors were encountered: