Skip to content

Commit

Permalink
Add force option to createRedirect
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertWSaunders committed Sep 26, 2018
1 parent f502b26 commit 6bc3267
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-netlify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ createRedirect({ fromPath: "/old-url", toPath: "/new-url", isPermanent: true })
createRedirect({ fromPath: "/url", toPath: "/zn-CH/url", Language: "zn" })
```

> 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).
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.

```sh
Expand Down
7 changes: 6 additions & 1 deletion packages/gatsby-plugin-netlify/src/create-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ export default async function writeRedirectsFile(
fromPath,
isPermanent,
redirectInBrowser, // eslint-disable-line no-unused-vars
force,
toPath,
...rest
} = redirect

let status = isPermanent ? `301` : `302`

if (force) status = status.concat(`!`)

// The order of the first 3 parameters is significant.
// The order for rest params (key-value pairs) is arbitrary.
const pieces = [
fromPath,
toPath,
isPermanent ? 301 : 302, // Status
status,
]

for (let key in rest) {
Expand Down

0 comments on commit 6bc3267

Please sign in to comment.