Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ We manage release notes in this file instead of the paginated Github Releases Pa

</details>

## v6.30.5

Date: 2026-08-18

### Patch Changes

- Fix double slash normalization for `useNavigate` colon urls

**Full Changelog**: [`v6.30.4...v6.30.5`](https://github.com/remix-run/react-router/compare/react-router@6.30.4...react-router@6.30.5)

## v6.30.4

Date: 2026-05-29
Expand Down Expand Up @@ -406,7 +416,7 @@ const router = createBrowserRouter(
patch("root", [route]);
}
},
},
}
);
```

Expand Down Expand Up @@ -1186,7 +1196,7 @@ let routes = createRoutesFromElements(
<Route index element={<Home />} />
<Route path="a" lazy={() => import("./a")} />
<Route path="b" lazy={() => import("./b")} />
</Route>,
</Route>
);
```

Expand Down
4 changes: 4 additions & 0 deletions packages/react-router/.changes/patch.fix-navigate-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix double slash normalization for `useNavigate` colon urls

- As a reminder, `navigate()` is only intended for navigations within the React Router application and not for external navigations to other domains
- This change may be a breaking bug fix if you are using `navigate` for external navigations
42 changes: 26 additions & 16 deletions packages/react-router/__tests__/resolvePath-test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { resolvePath } from "react-router";

describe("resolvePath", () => {
it("does not touch with protocol-less absolute paths", () => {
expect(resolvePath("//google.com")).toMatchObject({
pathname: "//google.com",
});

expect(resolvePath("//google.com/../../path")).toMatchObject({
pathname: "//google.com/../../path",
});

expect(resolvePath("//google.com?q=query#hash")).toMatchObject({
pathname: "//google.com",
search: "?q=query",
hash: "#hash",
});
});

it('resolves absolute paths irrespective of the "from" pathname', () => {
expect(resolvePath("/search", "/inbox")).toMatchObject({
pathname: "/search",
Expand Down Expand Up @@ -79,6 +63,32 @@ describe("resolvePath", () => {
spy.mockRestore();
});

it("handles relative paths with an embedded colon", () => {
expect(resolvePath("foo:bar", "/")).toMatchObject({
pathname: "/foo:bar",
});

expect(resolvePath("./foo:bar", "/")).toMatchObject({
pathname: "/foo:bar",
});

expect(resolvePath("../foo:bar", "/")).toMatchObject({
pathname: "/foo:bar",
});

expect(resolvePath("foo:bar", "/path")).toMatchObject({
pathname: "/path/foo:bar",
});

expect(resolvePath("./foo:bar", "/path")).toMatchObject({
pathname: "/path/foo:bar",
});

expect(resolvePath("../foo:bar", "/path")).toMatchObject({
pathname: "/foo:bar",
});
});

it('ignores trailing slashes on the "from" pathname when resolving relative paths', () => {
expect(resolvePath("../search", "/inbox/")).toMatchObject({
pathname: "/search",
Expand Down
20 changes: 4 additions & 16 deletions packages/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,23 +1145,11 @@ export function resolvePath(to: To, fromPathname = "/"): Path {

let pathname: string;
if (toPathname) {
if (isAbsoluteUrl(toPathname)) {
pathname = toPathname;
toPathname = removeDoubleSlashes(toPathname);
if (toPathname.startsWith("/")) {
pathname = resolvePathname(toPathname.substring(1), "/");
} else {
if (toPathname.includes("//")) {
let oldPathname = toPathname;
toPathname = removeDoubleSlashes(toPathname);
warning(
false,
`Pathnames cannot have embedded double slashes - normalizing ` +
`${oldPathname} -> ${toPathname}`
);
}
if (toPathname.startsWith("/")) {
pathname = resolvePathname(toPathname.substring(1), "/");
} else {
pathname = resolvePathname(toPathname, fromPathname);
}
pathname = resolvePathname(toPathname, fromPathname);
}
} else {
pathname = fromPathname;
Expand Down
Loading