React-router: Link component to support directory traversal

Created on 25 Jun 2019  Â·  3Comments  Â·  Source: ReactTraining/react-router

Version

"react-router-dom": "^5.0.1"

Test Case

https://codesandbox.io/s/react-router-plhuw

Steps to reproduce

Assuming props.match.url is /foo/bar, create a component:

<Link to={`${props.match.url}/../baz`}>go to baz</Link>

Expected Behavior

I would expect a transition to /foo/baz url.

Actual Behavior

Even the URL is changing to /foo/baz, react-router internally thinks the URL is /foo/bar/../baz, and fails on that.

However, if you reload a page - all works as expected.

All 3 comments

I think that is an issue related to the history library, that React Router uses. But yes, it should resolve as much as possible.

See #5127

@timdorr Actually, there are clear answers to both questions: 1st – relative paths in <Route /> is only possible for path relative to the current location (parent location), but not to any higher level. 2nd – relative paths in <Link /> is possible to any level, because that is what is defined in the related RFC. Any other way of path resolving is unexpected and differs from the way that <a /> resolves paths.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imWildCat picture imWildCat  Â·  3Comments

ArthurRougier picture ArthurRougier  Â·  3Comments

winkler1 picture winkler1  Â·  3Comments

maier-stefan picture maier-stefan  Â·  3Comments

alexyaseen picture alexyaseen  Â·  3Comments