-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into pr/apollo
- Loading branch information
Showing
175 changed files
with
4,830 additions
and
2,742 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
id: useCanGoBack | ||
title: useCanGoBack hook | ||
--- | ||
|
||
The `useCanGoBack` hook returns a boolean representing if the router history can safely go back without exiting the application. | ||
|
||
> ⚠️ The following new `useCanGoBack` API is currently _experimental_. | ||
## useCanGoBack returns | ||
|
||
- If the router history is not at index `0`, `true`. | ||
- If the router history is at index `0`, `false`. | ||
|
||
## Limitations | ||
|
||
The router history index is reset after a navigation with [`reloadDocument`](./NavigateOptionsType.md#reloaddocument) set as `true`. This causes the router history to consider the new location as the initial one and will cause `useCanGoBack` to return `false`. | ||
|
||
## Examples | ||
|
||
### Showing a back button | ||
|
||
```tsx | ||
import { useRouter, useCanGoBack } from '@tanstack/react-router' | ||
|
||
function Component() { | ||
const router = useRouter() | ||
const canGoBack = useCanGoBack() | ||
|
||
return ( | ||
<div> | ||
{canGoBack ? ( | ||
<button onClick={() => router.history.back()}>Go back</button> | ||
) : null} | ||
|
||
{/* ... */} | ||
</div> | ||
) | ||
} | ||
``` |
Oops, something went wrong.