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

[Bug]: Can't start route with @ within Layout Routes #8699

Closed
theostavrides opened this issue Mar 4, 2022 · 10 comments
Closed

[Bug]: Can't start route with @ within Layout Routes #8699

theostavrides opened this issue Mar 4, 2022 · 10 comments
Labels

Comments

@theostavrides
Copy link
Contributor

theostavrides commented Mar 4, 2022

What version of React Router are you using?

react-router-dom 6.2.2

Steps to Reproduce

  1. Set up routes like so:
<Routes>
    <Route element={<Layout />}>
        <Route path=":id" element={<Chat />} />
    </Route>
</Routes>
  1. Navigate to /@tom in the browser

Expected Behavior

/@tom should match path=":id", and render the element to the screen

Actual Behavior

The path does not match and this message is printed in the console:
index.tsx:25 No routes matched location "/@tom"

Notes

This issue is related to #8563, which was put into release 6.2.2.

@theostavrides theostavrides changed the title [Bug]: Can't start route with @ or ~ symbols [Bug]: Can't start route with special symbols within Layout Routes Mar 4, 2022
@theostavrides theostavrides changed the title [Bug]: Can't start route with special symbols within Layout Routes [Bug]: Can't start route with @ within Layout Routes Mar 4, 2022
@brophdawg11
Copy link
Contributor

Relates to #8525 (comment). Probably needs a closer look at the spec w.r.t @ as a reserved character

@theostavrides
Copy link
Contributor Author

theostavrides commented Mar 4, 2022

@brophdawg11 - please note that the @ character already works in 6.2.2, just not within layout routes.

    <Router>
      <Routes>
        <Route path="/:id" element={<p>works with '/@test'</p>}/>
        <Route path="/nested/:id" element={<p>works with '/nested/@test'</p>}/>
      </Routes>
    </Router>

My PR fixes this issue

@YousefED
Copy link

I was running into the same issue and agree with @theostavrides:

  • The character already works for non-nested routes
  • The character is commonplace in website URLs, for example when showing a profilepage on /@username

@shamsup
Copy link
Contributor

shamsup commented Mar 31, 2022

In #8563 I was specifically only including the unreserved characters with the idea that the whitelist could be expanded if needed. Of the reserved characters in the RFC, only !'()* are not touched by encodeURIComponent, but the RFC also says in section 3.3 that @ (as well as : and any sub-delims from 2.2) can be included in paths:

pchar = unreserved / pct-encoded / sub-delims / ":" / "@"

@kgamecarter
Copy link

kgamecarter commented Apr 16, 2022

Not merged PR yet.
I fix the bug by patch-package in 6.3.0

https://gist.github.com/kgamecarter/b64731e71aeecaa373aa31f81f8a1a43

@kgamecarter
Copy link

the #8877 will release in 6.4.0?

@brophdawg11
Copy link
Contributor

Hey folks! We've been doing some work lately to ensure that we can fully support special characters in paths and params etc. If anyone has a moment and would like to give react-router-dom@6.4.3-pre.1 a spin with any special character use-cases you have in the wild, we'd love any feedback on whether it's working as expected for you 🙌

Here's a stackblitz with some example routes, so feel free to fork it and add any special scenarios you have in your apps and let us know if anything seems off!

@kurdin
Copy link

kurdin commented Dec 21, 2022

In new versions of react-router-dom 6.5.x and 6.6.x special characters like @ or ~ does not work in path for route. If you have the same problem, downgrade to 6.4.x.

Here is updated stackblitz from @brophdawg11 with example of broken routes using @ and ~

@mattfysh
Copy link

Is there a way to downgrade while using remix? I've given up on trying to get this working with the filesystem-based routing, and now attempting to define a route in remix.config.js as /@:userId ... but it's also not working

@brophdawg11
Copy link
Contributor

You can still use special characters, but dynamic parameters (:param) are required to be full url segments. 6.5.0 included a fix to remove inadvertent support for partial params (/@:param). There's a suggested approach to follow in the release notes if your app was relying on this buggy behavior previously.

I'm going to close this issue out since I think this specific issue has been fixed since 6.4.3 but we missed closing it upon release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants