Skip to content

Commit d640fee

Browse files
tordansLekoArts
andauthored
chore(docs): Add section about navigate(-1) (#36184)
* Gatsby Link: Add section about `navigate(-1)` * Update gatsby-link.md Co-authored-by: Lennart <[email protected]>
1 parent 5d2528e commit d640fee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/docs/reference/built-in-components/gatsby-link.md

+6
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ const Form = () => (
290290
)
291291
```
292292

293+
### Navigate to the previous page
294+
295+
You can use `navigate(-1)` to go to a previously visited route. This is [Reach Router's](https://reach.tech/router/api/navigate) way of using `history.back()`. You can use any number as it uses [`history.go()`](https://developer.mozilla.org/en-US/docs/Web/API/History/go) under the hood. The `delta` parameter will be the number you pass in to `navigate()`.
296+
297+
If you want to check if there was a previous route you should [pass in an explicit state](#pass-state-as-props-to-the-linked-page) from your previously clicked internal link.
298+
293299
## Add the path prefix to paths using `withPrefix`
294300

295301
It is common to host sites in a sub-directory of a site. Gatsby lets you [set

0 commit comments

Comments
 (0)