remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.36k stars 10.34k forks source link

Relative Path Links not working #10998

Closed kentcdodds closed 1 year ago

kentcdodds commented 1 year ago

What version of Remix are you using?

2.2.0

Are all your remix dependencies & dev-dependencies using the same version?

Steps to Reproduce

npx --yes create-remix@latest --template --install https://github.com/epicweb-dev/full-stack-foundations/tree/main/exercises/02.routing/02.solution.links link-bug
cd link-bug
npm run dev

Open http://localhost:3000/users/kody/notes

Notice the "Back to Kody" link changes based on whether you're on /users/kody/notes vs /users/kody/notes/whatever.

More info here: https://www.loom.com/share/0e7be5f39c4e4e58afacc96feb0fc730

<Routes>
  <Route file="root.tsx">
    <Route index file="routes/index.tsx" />
    <Route path="users/kody" file="routes/users+/kody.tsx" />
    <Route path="users/kody/notes" file="routes/users+/kody_+/notes.tsx">
      <Route index file="routes/users+/kody_+/notes.index.tsx" />
      <Route path="some-note-id" file="routes/users+/kody_+/notes.some-note-id.tsx" />
    </Route>
  </Route>
</Routes>

Trying to add this to the users/kody/notes route and it's not working the way I want:

<Link to=".." relative="path" className="underline">
    Back to Kody
</Link>

Expected Behavior

I expect to be able to use relative="path" and have that be relative to the path of the route I'm rendering within. As @ryanflorence said:

It should be relative to the “route in context” path, not the url

Actual Behavior

The relative path is currently relative to the url

brophdawg11 commented 1 year ago

Fixed by #11006 - will be available in the next release 👍

github-actions[bot] commented 1 year ago

🤖 Hello there,

We just published version 6.19.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

github-actions[bot] commented 1 year ago

🤖 Hello there,

We just published version 6.19.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

kentcdodds commented 1 year ago

I've verified this is working. Thank you!

lpsinger commented 12 months ago

I expect to be able to use relative="path" and have that be relative to the path of the route I'm rendering within. As @ryanflorence said:

It should be relative to the “route in context” path, not the url

I think that the documentation is a bit ambiguous on this point:

By default, links are relative to the route hierarchy (relative="route"), so .. will go up one Route level. Occasionally, you may find that you have matching URL patterns that do not make sense to be nested, and you'd prefer to use relative path routing. You can opt into this behavior with relative="path":

Would it be possible to update the docs to clarify that relative="path" routing is relative to the path of the current route module, not the full path of the current URL?

brophdawg11 commented 12 months ago

@lpsinger Thanks for the call out - I just updated the docs to be a bit clearer in c47464c7e51c38cdf21a9fc2db81248daee2d171