Capítulo 55 de 57
The @tanstack/router/create-route-property-order ESLint rule enforces a specific ordering of type-inference-sensitive properties passed to createRoute, createFileRoute, createRootRoute, and createRootRouteWithContext, because TypeScript resolves these properties' types in the order they appear in the object literal.
beforeLoad and loader depend on inferred types from earlier properties (e.g. loader's context argument type depends on what beforeLoad returns); if loader is written before beforeLoad in the object literal, TypeScript can't yet infer the context shape.params, validateSearch → loaderDeps, search.middlewares, ssr → context → beforeLoad → loader → onEnter, onStay, onLeave, head, scripts, headers, remountDeps.component, notFoundComponent, staticData) don't depend on inference order and can be placed anywhere.createRoute, createFileRoute, createRootRoute, createRootRouteWithContext, all of which build route config objects subject to this inference chain.--fix can reorder properties automatically.// Incorrect: loader before beforeLoad breaks context type inference
export const Route = createFileRoute('/path')({
loader: async ({ context }) => {
await context.queryClient.ensureQueryData(getQueryOptions(context.hello))
},
beforeLoad: () => ({ hello: 'world' }),
})
// Correct: beforeLoad before loader
export const Route = createFileRoute('/path')({
beforeLoad: () => ({ hello: 'world' }),
loader: async ({ context }) => {
await context.queryClient.ensureQueryData(getQueryOptions(context.hello))
},
})
beforeLoad before loader fixes type inference of context.hello inside the loader.beforeLoad before loader (and follow the full documented order) so downstream properties get correctly inferred context/dependency types.eslint --fix handle reordering automatically rather than manually tracking the sequence.beforeLoad's return value feeds into loader's context argument.