diff --git a/docs/API.md b/docs/API.md index f5b0c169b6..d629daeafb 100644 --- a/docs/API.md +++ b/docs/API.md @@ -350,7 +350,7 @@ Called on routes when the location changes, but the route itself neither enters If `callback` is listed as a 4th argument, this hook will run asynchronously, and the transition will block until `callback` is called. -##### `onLeave()` +##### `onLeave(prevState)` Called when a route is about to be exited. diff --git a/docs/Glossary.md b/docs/Glossary.md index 366991e234..ee1d49052b 100644 --- a/docs/Glossary.md +++ b/docs/Glossary.md @@ -66,10 +66,10 @@ A *hash* is a string that represents the hash portion of the URL. It is synonymo ## LeaveHook ```js -type LeaveHook = () => any; +type LeaveHook = (prevState: RouterState) => any; ``` -A *leave hook* is a user-defined function that is called when a route is about to be unmounted. +A *leave hook* is a user-defined function that is called when a route is about to be unmounted. It receives the previous [router state](#routerstate) as its first argument. ## Location diff --git a/modules/__tests__/transitionHooks-test.js b/modules/__tests__/transitionHooks-test.js index 0e40a4a128..586428a5f1 100644 --- a/modules/__tests__/transitionHooks-test.js +++ b/modules/__tests__/transitionHooks-test.js @@ -104,8 +104,9 @@ describe('When a router enters a branch', function () { expect(nextState.routes).toContain(InboxRoute) expect(replace).toBeA('function') }, - onLeave() { + onLeave(prevState) { expect(this).toBe(InboxRoute) + expect(prevState.routes).toContain(InboxRoute) } } @@ -173,8 +174,9 @@ describe('When a router enters a branch', function () { expect(nextState.routes).toContain(DashboardRoute) expect(replace).toBeA('function') }, - onLeave() { + onLeave(prevState) { expect(this).toBe(DashboardRoute) + expect(prevState.routes).toContain(DashboardRoute) }, childRoutes: [ NewsFeedRoute, InboxRoute, RedirectToInboxRoute, MessageRoute, UserRoute ] }