Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

404
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!