Skip to content
Source
Sign inSign up
TanStack/router

feat(router-core): pass destination location to route lifecycle hooks #8774

OpenisihigameKoudai(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8774/headopened

Showing 13 changed files with 12 additions and 3 deletions (loading 10).

x
0 of 13 viewed, 13 left
5 additions and 0 deletions.changeset/lifecycle-destination-location.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/router-core': minor
+---
+​
+Pass the destination location to `onEnter`, `onStay` and `onLeave`. The hooks now receive a second argument, `RouteLifecycleContext`, whose `location` is the location the router is navigating to - the newly matched branch for `onEnter`/`onStay`, and the destination that replaces the leaving route for `onLeave`. Existing one-parameter hooks are unaffected.
6 additions and 3 deletionsdocs/router/api/router/RouteOptionsType.mdModified
View file
@@ -277,23 +277,26 @@
​
### `onEnter` property
​
-- Type: `(match: RouteMatch) => void`
+- Type: `(match: RouteMatch, context: RouteLifecycleContext) => void`
- Optional
- A function that will be called when a route is matched and loaded after not being matched in the previous location.
+- `context.location` is the destination the router is navigating to.
- Routes below an error or not-found boundary do not enter the active route lifecycle. The boundary itself remains active. A previously hidden route receives `onEnter` when a navigation makes it active again.
​
### `onStay` property
​
-- Type: `(match: RouteMatch) => void`
+- Type: `(match: RouteMatch, context: RouteLifecycleContext) => void`
- Optional
- A function that will be called when a route is matched and loaded after being matched in the previous location.