Skip to content

Commit e1e55c9

Browse files
tyhoppLekoArts
andauthored
chore(docs): Update FS route api client only splat description (#34546)
Co-authored-by: Lennart <[email protected]>
1 parent e9cd0ba commit e1e55c9

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

docs/docs/reference/routing/file-system-route-api.md

+24-4
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,32 @@ You can use square brackets (`[ ]`) in the file path to mark any dynamic segment
214214

215215
#### Splat routes
216216

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]`).
218218

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:
221220

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+
export default function ImagePage({ params }) {
226+
const param = 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+
export default function ImagePage({ params }) {
235+
const param = 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.
223243

224244
### Examples
225245

0 commit comments

Comments
 (0)