Skip to content

Commit ec02271

Browse files
committed
allow spa redirects to same origin
1 parent e2130f5 commit ec02271

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/react-router/lib/rsc/browser.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function createCallServer({
140140
Promise.resolve(payloadPromise)
141141
.then(async (payload) => {
142142
if (payload.type === "redirect") {
143-
if (payload.reload) {
143+
if (payload.reload || isExternalLocation(payload.location)) {
144144
window.location.href = payload.location;
145145
return () => {};
146146
}
@@ -163,7 +163,7 @@ export function createCallServer({
163163
globalVar.__routerActionID <= actionId
164164
) {
165165
if (rerender.type === "redirect") {
166-
if (rerender.reload) {
166+
if (rerender.reload || isExternalLocation(rerender.location)) {
167167
window.location.href = rerender.location;
168168
return;
169169
}
@@ -1047,3 +1047,8 @@ function debounce(callback: (...args: unknown[]) => unknown, wait: number) {
10471047
timeoutId = window.setTimeout(() => callback(...args), wait);
10481048
};
10491049
}
1050+
1051+
function isExternalLocation(location: string) {
1052+
const newLocation = new URL(location, window.location.href);
1053+
return newLocation.origin !== window.location.origin;
1054+
}

packages/react-router/lib/rsc/server.rsc.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,13 +887,10 @@ function generateRedirectResponse(
887887
redirect = stripBasename(redirect, basename) || redirect;
888888
}
889889

890-
const isExternal = isAbsoluteUrl(redirect);
891-
892890
let payload: RSCRedirectPayload = {
893891
type: "redirect",
894892
location: redirect,
895-
reload:
896-
isExternal || response.headers.get("X-Remix-Reload-Document") === "true",
893+
reload: response.headers.get("X-Remix-Reload-Document") === "true",
897894
replace: response.headers.get("X-Remix-Replace") === "true",
898895
status: response.status,
899896
actionResult,

0 commit comments

Comments
 (0)