Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

459
Vistas
How to redirect in nuxt3 refore routing completed

I'm trying to setup a boilerplate in nuxt3 which checks before each request if the access to the current path/route is allowed.

Currently I've tested two different approches but both didn't work as expected:

  1. using a middleware/test.ts file and calling it with middleware: ["test"].
  2. using a composables/useFoo.ts file and calling it with const foo = useFoo() inside of app.vue

Both solutions have an empty exported default function which only contains a console.log statement. The statement will be printed to the console at the initial load but not before/after change the route after clicking a NuxtLink. Is there any other solution to validate if the requested path is allowed including navitation with NuxtLink?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Im having a similar problem and looking for the same solution i guess , extending pages with (hooks) is the only thing i found that can meddle with the routes

hooks: {
    'pages:extend' (pages) {
      pages.push(
        {
          "name": "index",
          "path": "/",
          "children": [],
          "file": resolve(__dirname, 'pages/test.vue')
        },
      )
    }
  },

First thing i noticed is this can overtake behaviour nuxts own vue-router thats automatically build-up using my pages directory. But the second thing i noticed is unlike exendRoutes i wont take the following parameter: "beforeEnter: [fn()],

So i still can't figure out how to match or redirect in the routing lifecycle....

But my issue was the same as yours i need to guard navigation... in my case. I got nested pages e.g. :

  • [_Category] > [_BRAND] > products
  • [_Category] > [_GROUP] > products

Vue-Router automatic router setup allways takes me to brand... I need a way to check the param and navigate to the corresponding route brand/group.

This seemed like a solution : defineNuxtRouteMiddleware, addRouterMiddleWare, definepagemeta. But i couldnt import addRouterMiddleWare, definepagemeta.

Maybe one of you has more luck ..

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda