Skip to content

Commit e1d354e

Browse files
RobertWSaunderspieh
authored andcommitted
feat(gatsby-plugin-netlify): add force option to createRedirect (#8521)
1 parent 7bfb4b0 commit e1d354e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: packages/gatsby-plugin-netlify/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ createRedirect({ fromPath: "/old-url", toPath: "/new-url", isPermanent: true })
118118
createRedirect({ fromPath: "/url", toPath: "/zn-CH/url", Language: "zn" })
119119
```
120120

121+
> NOTE: You can pass the `force` option to override existing content in the path. This is particularly useful for domain alias redirects. See the Netlify documentation on this option [here](https://www.netlify.com/docs/redirects/#structured-configuration).
122+
121123
You can also create a `_redirects` file in the `static` folder for the same effect. Any programmatically created redirects will be appended to the file.
122124

123125
```sh

Diff for: packages/gatsby-plugin-netlify/src/create-redirects.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ export default async function writeRedirectsFile(
1919
fromPath,
2020
isPermanent,
2121
redirectInBrowser, // eslint-disable-line no-unused-vars
22+
force,
2223
toPath,
2324
...rest
2425
} = redirect
2526

27+
let status = isPermanent ? `301` : `302`
28+
29+
if (force) status = status.concat(`!`)
30+
2631
// The order of the first 3 parameters is significant.
2732
// The order for rest params (key-value pairs) is arbitrary.
2833
const pieces = [
2934
fromPath,
3035
toPath,
31-
isPermanent ? 301 : 302, // Status
36+
status,
3237
]
3338

3439
for (let key in rest) {

0 commit comments

Comments
 (0)