Skip to content
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

[V6] [Bug] .. navigation not working on the end of to path #8174

Closed
fxOne opened this issue Oct 28, 2021 · 1 comment
Closed

[V6] [Bug] .. navigation not working on the end of to path #8174

fxOne opened this issue Oct 28, 2021 · 1 comment

Comments

@fxOne
Copy link

fxOne commented Oct 28, 2021

Version

react-router-dom@v6.0.0-beta.8

Steps to reproduce

I have the following route: /baseId/pagePath/inpectorPage/deleteDialog/id
If I use the following code:

const navigate = useNavigate();
navigate('..');

The route is resolved to /baseId/pagePath/inpectorPage which is correct.
But as I need to preplace the baseId I'm using the following code:

const navigate = useNavigate();
const location = useLocation();
navigate(`${location.pathname.replace('baseId', 'newBaseId')}/..`);

The result is /newBaseId/pagePath/inpectorPage/deleteDialog. The .. navigation goes only one folder up instead of the expected one component.

I would expect the issue is base on the check if .. is on the start of the to path:

if (toPathname.startsWith("..")) {

@mjackson
Copy link
Member

The .. segment only traverses up routes when it's placed at the beginning of a to value, before any other path segments.

To achieve what you're trying to do here I'd use useResolvedPath("..").replace('baseId', 'newBaseId') instead. That should get you where you want to go.

brophdawg11 added a commit that referenced this issue Mar 27, 2024
Co-authored-by: Matt Brophy <matt@brophy.org>
Co-authored-by: Pedro Cattori <pcattori@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants