@@ -16,34 +16,41 @@ if you want to use SSR or DSG rendering.
16
16
17
17
## Install
18
18
19
- ` npm install gatsby-plugin-netlify `
19
+ ``` shell
20
+ npm install gatsby-plugin-netlify
21
+ ```
20
22
21
23
## How to use
22
24
23
- ``` javascript
24
- // In your gatsby-config.js
25
- plugins: [` gatsby-plugin-netlify` ]
25
+ Add ` gatsby-plugin-netlify ` to your ` gatsby-config ` :
26
+
27
+ ``` js:title=gatsby-config.js
28
+ module .exports = {
29
+ plugins: [` gatsby-plugin-netlify` ]
30
+ }
26
31
```
27
32
28
33
## Configuration
29
34
30
35
If you just need the critical assets, you don't need to add any additional config. However, if you want to add headers,
31
- remove default headers, or transform the given headers, you can use the following configuration options.
32
-
33
- ``` javascript
34
- plugins: [
35
- {
36
- resolve: ` gatsby-plugin-netlify` ,
37
- options: {
38
- headers: {}, // option to add more headers. `Link` headers are transformed by the below criteria
39
- allPageHeaders: [], // option to add headers for all pages. `Link` headers are transformed by the below criteria
40
- mergeSecurityHeaders: true , // boolean to turn off the default security headers
41
- mergeCachingHeaders: true , // boolean to turn off the default caching headers
42
- transformHeaders : (headers , path ) => headers, // optional transform for manipulating headers under each path (e.g.sorting), etc.
43
- generateMatchPathRewrites: true , // boolean to turn off automatic creation of redirect rules for client only paths
36
+ remove default headers, or transform the given headers, you can use the following configuration options:
37
+
38
+ ``` js:title=gatsby-config.js
39
+ module .exports = {
40
+ plugins: [
41
+ {
42
+ resolve: ` gatsby-plugin-netlify` ,
43
+ options: {
44
+ headers: {}, // option to add more headers. `Link` headers are transformed by the below criteria
45
+ allPageHeaders: [], // option to add headers for all pages. `Link` headers are transformed by the below criteria
46
+ mergeSecurityHeaders: true , // boolean to turn off the default security headers
47
+ mergeCachingHeaders: true , // boolean to turn off the default caching headers
48
+ transformHeaders : (headers , path ) => headers, // optional transform for manipulating headers under each path (e.g.sorting), etc.
49
+ generateMatchPathRewrites: true , // boolean to turn off automatic creation of redirect rules for client only paths
50
+ },
44
51
},
45
- },
46
- ]
52
+ ]
53
+ }
47
54
```
48
55
49
56
### Headers
@@ -101,25 +108,30 @@ You can validate the `_headers` config through the [Netlify playground app](http
101
108
102
109
### Redirects
103
110
104
- You can create redirects using the [ ` createRedirect ` ] ( https://www.gatsbyjs.org/docs/actions/#createRedirect ) action.
111
+ You can create redirects using the
112
+ [ ` createRedirect ` ] ( https://www.gatsbyjs.com/docs/reference/config-files/actions/#createRedirect ) action.
105
113
106
114
In addition to the options provided by the Gatsby API, you can pass these options specific to this plugin:
107
115
108
- | Attribute | Description |
109
- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
110
- | ` force ` | Overrides existing content in the path. This is particularly useful for domain alias redirects. See [ the Netlify documentation for this option] ( https://www.netlify.com/docs/redirects/#structured-configuration ) . |
111
- | ` statusCode ` | Overrides the HTTP status code which is set to ` 302 ` by default or ` 301 ` when [ ` isPermanent ` ] ( https://www.gatsbyjs.org /docs/actions/#createRedirect ) is ` true ` . Since Netlify supports custom status codes, you can set one here. For example, ` 200 ` for rewrites, or ` 404 ` for a custom error page. See [ the Netlify documentation for this option] ( https://www.netlify.com/docs/redirects/#http-status-codes ) . |
116
+ | Attribute | Description |
117
+ | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
118
+ | ` force ` | Overrides existing content in the path. This is particularly useful for domain alias redirects. See [ the Netlify documentation for this option] ( https://www.netlify.com/docs/redirects/#structured-configuration ) . |
119
+ | ` statusCode ` | Overrides the HTTP status code which is set to ` 302 ` by default or ` 301 ` when [ ` isPermanent ` ] ( https://www.gatsbyjs.com /docs/reference/config-files /actions/#createRedirect ) is ` true ` . Since Netlify supports custom status codes, you can set one here. For example, ` 200 ` for rewrites, or ` 404 ` for a custom error page. See [ the Netlify documentation for this option] ( https://www.netlify.com/docs/redirects/#http-status-codes ) . |
112
120
113
121
An example:
114
122
115
- ``` javascript
116
- createRedirect ({ fromPath: ' /old-url' , toPath: ' /new-url' , isPermanent: true })
117
- createRedirect ({ fromPath: ' /url' , toPath: ' /zn-CH/url' , Language: ' zn' })
118
- createRedirect ({
119
- fromPath: ' /url_that_is/not_pretty' ,
120
- toPath: ' /pretty/url' ,
121
- statusCode: 200 ,
122
- })
123
+ ``` js:title=gatsby-node.js
124
+ exports .createPages = ({ actions }) => {
125
+ const { createRedirect } = actions
126
+
127
+ createRedirect ({ fromPath: ' /old-url' , toPath: ' /new-url' , isPermanent: true })
128
+ createRedirect ({ fromPath: ' /url' , toPath: ' /zn-CH/url' , Language: ' zn' })
129
+ createRedirect ({
130
+ fromPath: ' /url_that_is/not_pretty' ,
131
+ toPath: ' /pretty/url' ,
132
+ statusCode: 200 ,
133
+ })
134
+ }
123
135
```
124
136
125
137
You can also create a ` _redirects ` file in the ` static ` folder for the same effect. Any programmatically created
@@ -134,10 +146,10 @@ redirects will be appended to the file.
134
146
You can validate the ` _redirects ` config through the [ Netlify playground app] ( https://play.netlify.com/redirects ) .
135
147
136
148
Redirect rules are automatically added for
137
- [ client only paths] ( https://www.gatsbyjs.org /docs/client-only-routes-and-user-authentication ) . The plugin uses the
138
- [ matchPath] ( https://www.gatsbyjs.org /docs/gatsby-internals-terminology/#matchpath ) syntax to match all possible requests
139
- in the range of your client-side routes and serves the HTML file for the client-side route. Without it, only the exact
140
- route of the client-side route works.
149
+ [ client only paths] ( https://www.gatsbyjs.com /docs/how-to/routing/ client-only-routes-and-user-authentication/ ) . The
150
+ plugin uses the [ matchPath] ( https://www.gatsbyjs.com /docs/gatsby-internals-terminology/#matchpath ) syntax to match all
151
+ possible requests in the range of your client-side routes and serves the HTML file for the client-side route. Without
152
+ it, only the exact route of the client-side route works.
141
153
142
154
If those rules are conflicting with custom rules or if you want to have more control over them you can disable them in
143
155
[ configuration] ( #configuration ) by setting ` generateMatchPathRewrites ` to ` false ` .
0 commit comments