Skip to content

Commit 0616f6e

Browse files
nvartolomeitimdorr
authored andcommitted
Fix setRouteLeaveHook references in docs (#3489)
* Add setRouteLeaveHook to API documentation * Fix setRouteLeaveHook reference in Glossary * Update listenBeforeLeavingRoute doc to match API docs
1 parent b31d75e commit 0616f6e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

docs/API.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ Go back one entry in the history.
201201
##### `goForward()`
202202
Go forward one entry in the history.
203203

204+
##### `setRouteLeaveHook(route, hook)`
205+
Registers the given hook function to run before leaving the given route.
206+
207+
During a normal transition, the hook function receives the next location as its only argument and can return either a prompt message (string) to show the user, to make sure they want to leave the page; or `false`, to prevent the transition. Any other return value will have no effect.
208+
209+
During the beforeunload event (in browsers) the hook receives no arguments.
210+
In this case it must return a prompt message to prevent the transition.
211+
212+
Returns a function that may be used to unbind the listener.
213+
214+
You don't need to manually tear down the route leave hook in most cases. We automatically remove all attached route leave hooks after leaving the associated route.
215+
204216
##### `createPath(pathOrLoc, query)`
205217
Stringifies the query into the pathname, using the router's config.
206218

docs/Glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ type Router = {
244244
go(n: number) => void;
245245
goBack() => void;
246246
goForward() => void;
247-
setRouteLeaveHook(hook: RouteHook) => Function;
247+
setRouteLeaveHook(route: Route, hook: RouteHook) => Function;
248248
isActive(location: LocationDescriptor, indexOnly: boolean) => void;
249249
};
250250
```

modules/createTransitionManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ export default function createTransitionManager(history, routes) {
198198
* Registers the given hook function to run before leaving the given route.
199199
*
200200
* During a normal transition, the hook function receives the next location
201-
* as its only argument and must return either a) a prompt message to show
202-
* the user, to make sure they want to leave the page or b) false, to prevent
203-
* the transition.
201+
* as its only argument and can return either a prompt message (string) to show the user,
202+
* to make sure they want to leave the page; or `false`, to prevent the transition.
203+
* Any other return value will have no effect.
204204
*
205205
* During the beforeunload event (in browsers) the hook receives no arguments.
206206
* In this case it must return a prompt message to prevent the transition.

0 commit comments

Comments
 (0)