Caution
This class has been deprecated and will be removed in the next major version of TanStack Router. Please use the getRouteApi function instead.
The RouteApi class provides type-safe version of common hooks like useParams, useSearch, useRouteContext, useNavigate, useLoaderData, and useLoaderDeps that are pre-bound to a specific route ID and corresponding registered route types.
The RouteApi constructor accepts a single argument: the options that will be used to configure the RouteApi instance.
import { RouteApi } from '@tanstack/react-router'
const routeApi = new RouteApi({ id: '/posts' })
export function PostsPage() {
const posts = routeApi.useLoaderData()
// ...
}
import { RouteApi } from '@tanstack/react-router'
const routeApi = new RouteApi({ id: '/posts' })
export function PostsPage() {
const posts = routeApi.useLoaderData()
// ...
}
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.