T
TanStack6mo ago
compatible-crimson

Apply Middlewares globally

Is there a way to apply middlewares globally to every page? I'm using this middleware: middlewares: [retainSearchParams(['rootValue'])] It does exactly what I need, it retains certain query parameters across route changes. However, it only works when added to each page’s createFileRoute. I’d like to apply it globally to all pages. Adding it to createRootRoute doesn’t seem to apply it to child routes. Is there a way to apply such middleware globally, without having to add it manually to every single route? Would appreciate any tips!
1 Reply
compatible-crimson
compatible-crimsonOP6mo ago
nvm, it actually does work globally when using zod together with tanstack/zod-adapter. Turns out the issue was probably with my manual validation, not the middleware itself.

Did you find this page helpful?