Skip to content

Error Redirected  #3316

@yoonasy

Description

@yoonasy

Version

3.4.3

Reproduction link

http://xxx.xxx

Steps to reproduce

vue.runtime.esm.js?2b0e:1888 Error: Redirected when going from "/home" to "/product" via a navigation guard.

home.vue

this.$router.push('/product')

a router guard permission.js

async function initRouter (router) {
  router.beforeEach(async (to, from, next) => {
    NProgress.done(true)
    NProgress.remove()
    NProgress.start()

    const token = store.state.user.token
    const info = store.state.user.info

    if (to.meta.requireAuth && !token) {
      return next({ // Here is an error,Multiple redirection?
        path: '/login',
        query: { redirect: to.fullPath },
      })
    } else if (to.path === '/login' && token) {
      return next({ path: '/home' })
    }

    if (token && !info) {
      await store.dispatch('user/getInfo')
    }

    store.commit('user/SET_INIT', true)

    next()
  })

  router.afterEach(() => {
    NProgress.done()
  })
}

What is expected?

When redirecting, modify the redirect

What is actually happening?

error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions