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

Relative Path Links not working #10998

Closed
1 task done
kentcdodds opened this issue Nov 3, 2023 · 6 comments · Fixed by #11006
Closed
1 task done

Relative Path Links not working #10998

kentcdodds opened this issue Nov 3, 2023 · 6 comments · Fixed by #11006

Comments

@kentcdodds
Copy link
Member

What version of Remix are you using?

2.2.0

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

  • Yes

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 brophdawg11 transferred this issue from remix-run/remix Nov 6, 2023
@brophdawg11 brophdawg11 self-assigned this Nov 6, 2023
@brophdawg11 brophdawg11 linked a pull request Nov 8, 2023 that will close this issue
@brophdawg11
Copy link
Contributor

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

@brophdawg11 brophdawg11 added the awaiting release This issue have been fixed and will be released soon label Nov 13, 2023
@brophdawg11 brophdawg11 removed their assignment Nov 13, 2023
Copy link
Contributor

🤖 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!

Copy link
Contributor

🤖 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
Copy link
Member Author

I've verified this is working. Thank you!

@brophdawg11 brophdawg11 removed the awaiting release This issue have been fixed and will be released soon label Nov 22, 2023
@lpsinger
Copy link
Contributor

lpsinger commented Dec 5, 2023

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
Copy link
Contributor

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

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

Successfully merging a pull request may close this issue.

3 participants