You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/reference/routing/file-system-route-api.md
+24-4
Original file line number
Diff line number
Diff line change
@@ -214,12 +214,32 @@ You can use square brackets (`[ ]`) in the file path to mark any dynamic segment
214
214
215
215
#### Splat routes
216
216
217
-
Gatsby also supports _splat_ (or wildcard) routes, which are routes that will match _anything_ after the splat. These are less common, but still have use cases. As an example, suppose that you are rendering images from [S3](/docs/how-to/previews-deploys-hosting/deploying-to-s3-cloudfront/) and the URL is actually the key to the asset in AWS. Here is how you might create your file:
217
+
Gatsby also supports _splat_ (or wildcard) routes, which are routes that will match _anything_ after the splat. These are less common, but still have use cases. Use three periods in square brackets (`[...]`) in a file path to mark a page as a splat route. You can also name the parameter your page receives by adding a name after the three periods (`[...myNameKey]`).
218
218
219
-
-`src/pages/image/[...awsKey].js` will generate a route like `/image/*awsKey`
220
-
-`src/pages/image/[...].js` will generate a route like `/image/*`
219
+
As an example, suppose that you are rendering images from [S3](/docs/how-to/previews-deploys-hosting/deploying-to-s3-cloudfront/) and the URL is actually the key to the asset in AWS. Here is how you might create your file:
221
220
222
-
Three periods `...` mark a page as a splat route. Optionally, you can name the splat as well, which has the benefit of naming the key of the property that your component receives.
221
+
-`src/pages/image/[...].js` will generate a route like `/image/*`. `*` is accessible in your page's received properties with the key name `*`.
222
+
-`src/pages/image/[...awsKey].js` will generate a route like `/image/*awsKey`. `*awsKey` is accessible in your page's received properties with the key name `awsKey`.
223
+
224
+
```js:title=src/pages/image/[...].js
225
+
exportdefaultfunctionImagePage({ params }) {
226
+
constparam= params[`*`]
227
+
228
+
// When visiting a route like `image/hello/world`,
229
+
// the value of `param` is `hello/world`.
230
+
}
231
+
```
232
+
233
+
```js:title=src/pages/image/[...awsKey].js
234
+
exportdefaultfunctionImagePage({ params }) {
235
+
constparam= params[`awsKey`]
236
+
237
+
// When visiting a route like `image/hello/world`,
238
+
// the value of `param` is `hello/world`.
239
+
}
240
+
```
241
+
242
+
Splat routes may not live in the same directory as regular client only routes.
0 commit comments