From c7ca22443e0ea573f38b23669061185e01d2f9d7 Mon Sep 17 00:00:00 2001 From: Dominik Dorfmeister Date: Thu, 21 Mar 2024 11:18:01 +0100 Subject: [PATCH] feat: add useNavigate to RouteApi --- packages/react-router/src/route.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-router/src/route.ts b/packages/react-router/src/route.ts index 1ca938b71db..ef3065b9df8 100644 --- a/packages/react-router/src/route.ts +++ b/packages/react-router/src/route.ts @@ -20,6 +20,7 @@ import { import { BuildLocationFn, NavigateFn } from './RouterProvider' import { NotFoundError, notFound } from './not-found' import { LazyRoute } from './fileRoute' +import { useNavigate } from './useNavigate' export const rootRouteId = '__root__' as const export type RootRouteId = typeof rootRouteId @@ -530,6 +531,10 @@ export class RouteApi< return useLoaderData({ ...opts, from: this.id, strict: false } as any) } + useNavigate = () => { + return useNavigate({ from: this.id }) + } + notFound = (opts?: NotFoundError) => { return notFound({ routeId: this.id as string, ...opts }) }