-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Pass 'force' parameter for redirects #38640
Changes from 3 commits
fd2e5ba
b581952
2c37d59
838bdd9
cbf37c5
fd7cb06
51edb37
80cc170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from "react" | ||
import Layout from "../../../components/layout" | ||
|
||
const ExistingForcePage = () => { | ||
return ( | ||
<Layout> | ||
<h1>Existing Force</h1> | ||
</Layout> | ||
) | ||
} | ||
|
||
export default ExistingForcePage | ||
|
||
export const Head = () => <title>Existing Force</title> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -458,17 +458,28 @@ function getRoutesManifest(): RoutesManifest { | |||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// redirect routes | ||||||||||||||||||||||||||||||||||||||||||
for (const redirect of state.redirects.values()) { | ||||||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||||||
fromPath, | ||||||||||||||||||||||||||||||||||||||||||
toPath, | ||||||||||||||||||||||||||||||||||||||||||
statusCode, | ||||||||||||||||||||||||||||||||||||||||||
isPermanent, | ||||||||||||||||||||||||||||||||||||||||||
ignoreCase, | ||||||||||||||||||||||||||||||||||||||||||
redirectInBrowser, | ||||||||||||||||||||||||||||||||||||||||||
...platformSpecificFields | ||||||||||||||||||||||||||||||||||||||||||
} = redirect | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
addRoute({ | ||||||||||||||||||||||||||||||||||||||||||
path: redirect.fromPath, | ||||||||||||||||||||||||||||||||||||||||||
path: fromPath, | ||||||||||||||||||||||||||||||||||||||||||
type: `redirect`, | ||||||||||||||||||||||||||||||||||||||||||
toPath: redirect.toPath, | ||||||||||||||||||||||||||||||||||||||||||
toPath: toPath, | ||||||||||||||||||||||||||||||||||||||||||
status: | ||||||||||||||||||||||||||||||||||||||||||
redirect.statusCode ?? | ||||||||||||||||||||||||||||||||||||||||||
(redirect.isPermanent | ||||||||||||||||||||||||||||||||||||||||||
statusCode ?? | ||||||||||||||||||||||||||||||||||||||||||
(isPermanent | ||||||||||||||||||||||||||||||||||||||||||
? HTTP_STATUS_CODE.MOVED_PERMANENTLY_301 | ||||||||||||||||||||||||||||||||||||||||||
: HTTP_STATUS_CODE.FOUND_302), | ||||||||||||||||||||||||||||||||||||||||||
ignoreCase: redirect.ignoreCase, | ||||||||||||||||||||||||||||||||||||||||||
ignoreCase: ignoreCase, | ||||||||||||||||||||||||||||||||||||||||||
headers: BASE_HEADERS, | ||||||||||||||||||||||||||||||||||||||||||
platformSpecificFields, | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
otherwise this would not really match this (public) type gatsby/packages/gatsby/src/utils/adapter/types.ts Lines 47 to 64 in 5dbcf9e
(technically it does matches it, but this is more that shape of redirect is more about having platform specific fields as top level fields and not have actual Also with this as-is the current code in this PR in packages/gatsby-adapter-netlify/src/route-handler.ts wouldn't actually work as it does expect This change will need some adjustment in test added to packages/gatsby/src/utils/adapter/tests/manager.ts |
||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still trying to figure out how to test this, since
handleRoutesManifest
doesn't return anything to check against. Using the debugger, I can see the status being set to200!
within the method (and also parsing the conditions 🎉), but can't read the outputinjectEntries
writes topublic/_redirects
from the test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's split
handleRoutesManifest
into 2 functions - one that does most of the work and returns the_redirect
and_headers
content which we can assert and the other one (probably will keep existing name) that calls the new function and then callinjectEntries
with resultsThat would allow for easy assertion (without creating some kind of spy, mocks or allowing function to actually write the files out and then read that file back).
Does that sound fine?