-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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]: Route filename starting with escaped at-sign [@] does not match #846
Comments
Related: #819 @kentcdodds tried adding
|
From what I can tell, the
|
@soungrong see #819. I have a patch that works. Current implementation doesn't match paths that start with non-word character like @ or . |
@kiliman LGTM, thank you! |
The patch suggested in #819 (comment) actually fails one of the tests here https://github.com/remix-run/react-router/blob/main/packages/react-router/__tests__/matchPath-test.tsx#L156-L162 Here's what I've learned so far trying to debug this with my primitive understanding of
That said, nested paths without leading special characters currently match as expected, e.g. |
Yes, the patch does break the test /user2 matches /user. I'm actually trying to come up with the correct solution, but everything I've tried so far seems to break other tests. I'm still learning how the pattern matching process works. |
The underlying issue seems to have been fixed in react-router : remix-run/react-router#8877 |
I believe that this will be released in react-router 6.4.0. Until then I have been using a Makefile patch: patch-react-router:
# https://github.com/remix-run/react-router/pull/8877/files#diff-cf8c561ed8c0d6c0ace3e6be06dcceaa55f84f916d19f6d6247c208774982921R480
sed -i.bak "s/\[\.\~\-\]/\[\@\.\~\-\]/g" ./node_modules/react-router/main.js
sed -i.bak "s/\[\.\~\-\]/\[\@\.\~\-\]/g" ./node_modules/react-router/index.js
sed -i.bak "s/\[\.\~\-\]/\[\@\.\~\-\]/g" ./node_modules/react-router/react-router.development.js
sed -i.bak "s/\[\.\~\-\]/\[\@\.\~\-\]/g" ./node_modules/react-router/react-router.production.min.js
sed -i.bak "s/\[\.\~\-\]/\[\@\.\~\-\]/g" ./node_modules/react-router/umd/react-router.development.js
sed -i.bak "s/\[\.\~\-\]/\[\@\.\~\-\]/g" ./node_modules/react-router/umd/react-router.production.min.js Probably much better ways of doing this, but this seems to work until the upgrade is released. |
I had the same problem when using remix 1.7.2 For example
But |
I created a patch to backport React Router PR #9300 to React Router 6.3 which is the version pinned in Remix. This fix allows non-alphanumeric characters to start a route path. This means Currently this only patches the development build as the production files are minified. I will update the patch once I setup to build React Router locally. https://gist.github.com/kiliman/1a8eb57a6558c96d292bb913add5a178 |
Any news? |
I upgraded to the latest version of remix (v1.10.0-pre.5) which comes with react-router v6.6.1 - but it is still not possible to achieve this style of user profile URLs (a la Mastodon or TikTok) I've also tried defining the route manually in Are there no other workarounds? |
Is it possible to use parameterized pattern-matching with <Route path="/@:userId" element={<UserElement />}/> |
Not a permanent solution but it seems that with the latest (stable) version it is possible to handle this in export async function loader({ request, params }: LoaderArgs) {
let handle = params.handle.startsWith("@") ? params.handle.slice(1) : null;
if (!handle) {
throw new Response("Not Found", {
status: 404,
});
}
// ...
} |
Yes, that's what I finally did. Not as elegant as |
Just to summarize this issue before I close it:
This was confirmed by @brophdawg11 in RR 6.5.0 https://github.com/remix-run/react-router/releases/tag/react-router%406.5.0 and PR here remix-run/react-router#9506
|
Any updates on this? This is still broken in v1.12. The workarounds listed by @soungrong are useful but this still needs to be fixed. Having a set of urls start with a prefix followed by a dynamic segment is a pretty common occurrence. |
The reason is that we want the router to perform all routing requirements, and not have to create a wide dynamic segment then manually filter out values that do not begin with the intended prefix manually. What I mean by this is having to perform something like this in every nested route:
When the desired routing is The router should be the perfect place for this behaviour to be implemented |
Which Remix packages are impacted?
remix
(Remix core)@remix-run/react
What version of Remix are you using?
1.0.6
Steps to Reproduce
[@]hello.jsx
inapp/routes
https://example.com/@hello
Expected Behavior
The route matches successfully.
Actual Behavior
The text was updated successfully, but these errors were encountered: