Skip to content

Commit d6a4352

Browse files
Add JSDoc annotations to public API (#5573)
Add documentation for useMatchRoute and useNavigate hooks Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 7f809a8 commit d6a4352

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/react-router/src/Matches.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ export type UseMatchRouteOptions<
123123
MaskOptions<TRouter, TMaskFrom, TMaskTo> &
124124
MatchRouteOptions
125125

126+
/**
127+
* Create a matcher function for testing locations against route definitions.
128+
*
129+
* The returned function accepts standard navigation options (`to`, `params`,
130+
* `search`, etc.) and returns either `false` (no match) or the matched params
131+
* object when the route matches the current or pending location.
132+
*
133+
* Useful for conditional rendering and active UI states.
134+
*
135+
* @returns A `matchRoute(options)` function that returns `false` or params.
136+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook
137+
*/
126138
export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
127139
const router = useRouter()
128140

@@ -231,6 +243,15 @@ export function useMatches<
231243
} as any) as UseMatchesResult<TRouter, TSelected>
232244
}
233245

246+
/**
247+
* Read the full array of active route matches or select a derived subset.
248+
*
249+
* Useful for debugging, breadcrumbs, or aggregating metadata across matches.
250+
*
251+
* @returns The array of matches (or the selected value).
252+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook
253+
*/
254+
234255
/**
235256
* Read the full array of active route matches or select a derived subset.
236257
*

packages/react-router/src/useNavigate.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import type {
88
UseNavigateResult,
99
} from '@tanstack/router-core'
1010

11+
/**
12+
* Imperative navigation hook.
13+
*
14+
* Returns a stable `navigate(options)` function to change the current location
15+
* programmatically. Prefer the `Link` component for user-initiated navigation,
16+
* and use this hook from effects, callbacks, or handlers where imperative
17+
* navigation is required.
18+
*
19+
* Options:
20+
* - `from`: Optional route base used to resolve relative `to` paths.
21+
*
22+
* @returns A function that accepts `NavigateOptions`.
23+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useNavigateHook
24+
*/
1125
export function useNavigate<
1226
TRouter extends AnyRouter = RegisteredRouter,
1327
TDefaultFrom extends string = string,

0 commit comments

Comments
 (0)