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

Support base64 encoded ids on nested routes #8291

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/react-router/__tests__/matchRoutes-test.tsx
Expand Up @@ -12,9 +12,14 @@ function pickPaths(
}

describe("matchRoutes", () => {
let userEditRoute: RouteObject = {
path: "edit",
element: <h1>User Edit</h1>
};
let userProfileRoute: RouteObject = {
path: ":id",
element: <h1>User Profile</h1>
element: <h1>User Profile</h1>,
children: [userEditRoute]
};
let usersRoute: RouteObject = {
path: "/users",
Expand Down Expand Up @@ -88,6 +93,20 @@ describe("matchRoutes", () => {

it("matches nested dynamic routes correctly", () => {
expect(pickPaths(routes, "/users/mj")).toEqual(["/users", ":id"]);
expect(pickPaths(routes, "/users/mj/edit")).toEqual([
"/users",
":id",
"edit"
]);
});

it("matches nested dynamic routes with params ending in = (e.x. base64 encoded Id)", () => {
expect(pickPaths(routes, "/users/VXNlcnM6MQ==")).toEqual(["/users", ":id"]);
expect(pickPaths(routes, "/users/VXNlcnM6MQ==/edit")).toEqual([
"/users",
":id",
"edit"
]);
});

it("matches nested * routes correctly", () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/index.tsx
Expand Up @@ -1150,10 +1150,10 @@ function compilePath(
} else {
regexpSource += end
? "\\/*$" // When matching to the end, ignore trailing slashes
: // Otherwise, at least match a word boundary. This restricts parent
// routes to matching only their own words and nothing more, e.g. parent
: // Otherwise, match a word boundary or a proceeding /. The word boundary restricts
// parent routes to matching only their own words and nothing more, e.g. parent
// route "/home" should not match "/home2".
"(?:\\b|$)";
"(?:\\b|\\/|$)";
}

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