NuxtN
Nuxt2y ago
lp

Client-Side Middleware

Hello, I was wondering if it is possible to have a middleware runs only client-side and redirect if something is not set for example in local storage, etc.

export default defineNuxtRouteMiddleware((to, from) => {
  if (import.meta.server) return;

  if (to.path === '/test') {
    return navigateTo('/');
  }
});


Right now I am doing this test and I return if it is server let's say I have to access local storage, but I still see the test page beign render and after it redirects is there a way to fix this? Thanks!
Was this page helpful?