-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to force reload on redirect with `X-Remix-Reload-Document…
…` header (#10705) Co-authored-by: Matt Brophy <matt@brophy.org>
- Loading branch information
1 parent
2ab24cc
commit 46806a4
Showing
12 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"react-router": minor | ||
"react-router-dom": minor | ||
"react-router-dom-v5-compat": minor | ||
"react-router-native": minor | ||
"@remix-run/router": minor | ||
--- | ||
|
||
Add's a new `redirectDocument()` function which allows users to specify that a redirect from a `loader`/`action` should trigger a document reload (via `window.location`) instead of attempting to navigate to the redirected location via React Router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,3 +228,4 @@ | |
- smithki | ||
- istarkov | ||
- louis-young | ||
- robbtraister |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: redirectDocument | ||
new: true | ||
--- | ||
|
||
# `redirectDocument` | ||
|
||
This is a small wrapper around [`redirect`][redirect] that will trigger a document-level redirect to the new location instead of a client-side navigation. | ||
|
||
This is most useful when you have a React Router app living next to a separate app on the same domain and need to redirect from the React Router app to the other app via `window.location` instead of a React Router navigation: | ||
|
||
```jsx | ||
import { redirectDocument } from "react-router-dom"; | ||
|
||
const loader = async () => { | ||
const user = await getUser(); | ||
if (!user) { | ||
return redirectDocument("/otherapp/login"); | ||
} | ||
return null; | ||
}; | ||
``` | ||
|
||
## Type Declaration | ||
|
||
```ts | ||
type RedirectFunction = ( | ||
url: string, | ||
init?: number | ResponseInit | ||
) => Response; | ||
``` | ||
|
||
## `url` | ||
|
||
The URL to redirect to. | ||
|
||
```js | ||
redirectDocument("/otherapp/login"); | ||
``` | ||
|
||
## `init` | ||
|
||
The [Response][response] options to be used in the response. | ||
|
||
[response]: https://developer.mozilla.org/en-US/docs/Web/API/Response/Response | ||
[redirect]: ./redirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,7 @@ export { | |
Form, | ||
json, | ||
redirect, | ||
redirectDocument, | ||
useActionData, | ||
useAsyncError, | ||
useAsyncValue, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters