Skip to content

Fix: cant start route with @ within Layout Routes (#8699) #8700

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- shamsup
- shihanng
- shivamsinghchahar
- theostavrides
- thisiskartik
- timdorr
- turansky
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,32 @@ describe("Descendant <Routes> splat matching", () => {
</div>
`);
});
it("allows `@` to appear at the beginning", () => {
let renderer = renderNestedSplatRoute([
"/courses/react/@react-fundamentals",
]);
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<div>
<h1>
Courses
</h1>
<div>
<h1>
React
</h1>
<div>
<h1>
React Fundamentals
</h1>
<p>
The params are
{"*":"@react-fundamentals","splat":"@react-fundamentals"}
</p>
</div>
</div>
</div>
`);
});
it("allows url-encoded entities to appear at the beginning", () => {
let renderer = renderNestedSplatRoute([
"/courses/react/%20react-fundamentals",
Expand Down
41 changes: 41 additions & 0 deletions packages/react-router/__tests__/layout-routes-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ describe("A layout route", () => {
`);
});
describe("matches when a nested splat route begins with a special character", () => {
it("allows routes starting with `@`", () => {
let renderer: TestRenderer.ReactTestRenderer;
TestRenderer.act(() => {
renderer = TestRenderer.create(
<MemoryRouter initialEntries={["/@splat"]}>
<Routes>
<Route
element={
<div>
<h1>Layout</h1>
<Outlet />
</div>
}
>
<Route
path="*"
element={
<div>
<h1>Splat</h1>
</div>
}
/>
</Route>
</Routes>
</MemoryRouter>
);
});

expect(renderer.toJSON()).toMatchInlineSnapshot(`
<div>
<h1>
Layout
</h1>
<div>
<h1>
Splat
</h1>
</div>
</div>
`);
});
it("allows routes starting with `-`", () => {
let renderer: TestRenderer.ReactTestRenderer;
TestRenderer.act(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ function compilePath(
// Additionally, allow paths starting with `.`, `-`, `~`, and url-encoded entities,
// but do not consume the character in the matched path so they can match against
// nested paths.
"(?:(?=[.~-]|%[0-9A-F]{2})|\\b|\\/|$)";
"(?:(?=[@.~-]|%[0-9A-F]{2})|\\b|\\/|$)";
}

let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
Expand Down