app/middlewares
Control Vue navigation with global or named middleware.
Middleware runs during Vue Router navigation. Use it to check a session, redirect, or block access to a page.
// app/middlewares/auth.ts
export default defineVueMiddleware((to) => {
const user = useCurrentUser();
if (!user.value && to.path !== "/login") {
return "/login";
}
});Then reference its name from the page:
definePageMeta({
middleware: ["auth"],
});A file with the .global.ts suffix applies to every navigation:
app/middlewares/analytics.global.tsThese middleware functions belong to the Vue router. HTTP middleware, API-route authentication, and request validation remain in your backend.