Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

411
Visualizações
Nuxt redirect doen't work - how to make redierct process collectly in Nuxt.js apps

I've been used Nuxt.js(v2.15.7) as SPA web apps. But Redirecting doesn't work in my apps.

My apps is simple. User login the apps, and then move to home contents. login display made in pages/index.vue, and home contents made in pages/home.vue.

and I also have used "vuex" as state management. So, I made redirect process like below.

export default ({ store, redirect, route }: any) => {
    if (!store.state.user && (route.name !== 'index' || route.name !== 'auth-setPassword')) {
        redirect('/')
    }
    if (store.state.user && (route.name === 'index' || route.name === 'auth-setPassword')) {
        redirect('/home')
    }
}

If user finish login process, user info preserve state.user. Of user doen't finish login process, state.user always is null. this file placed in the plugins. and then add plugins file path in nuxt.config.ts like below.

export default{
・・・
plugins: [
    { src: '~/plugins/auth', ssr: false },
  ],
・・・
}

but it doesn't work. I always try like "localhost:3000/home" not logged in and move to the "home" contents.

and I try to use "window.onNuxtReady" in my redirect process like below.

export default ({ store, redirect, route }: any) => {
    if (!store.state.user && (route.name !== '/' || route.name !== 'auth-setPassword')) {
        (<any>window).onNuxtReady(() => {
            redirect('/')
        })
    }
    if (store.state.user && (route.name === '/' || route.name === 'auth-setPassword')) {
        (<any>window).onNuxtReady(() => {
            redirect('/home')
        })
    }
}

Redirect process was success but always show error message below.

NavigationDuplicated: Avoided redundant navigation to current location: "/".

Does anyone help me, how to redirect correctly in nuxt.js web apps?

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda