Use the getRouteApi() method like so:
import { getRouteApi } from '@tanstack/react-router'
// Somewhere in a component that's not inside your route file
function SomeNestedComponent() {
const routeApi = getRouteApi('/posts')
const data = routeApi.useLoaderData()
// Component code
}