Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于permission.js 中 next({...to,replace:true }) #2420

Open
whateveryoudo opened this issue Jul 28, 2019 · 2 comments
Open

关于permission.js 中 next({...to,replace:true }) #2420

whateveryoudo opened this issue Jul 28, 2019 · 2 comments

Comments

@whateveryoudo
Copy link

whateveryoudo commented Jul 28, 2019

` if (hasRoles) {
next()
} else {
try {
// get user info
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
const { roles } = await store.dispatch('user/getInfo')

      // generate accessible routes map based on roles
      const accessRoutes = await store.dispatch('permission/generateRoutes', roles)

      // dynamically add accessible routes
      router.addRoutes(accessRoutes)

      // hack method to ensure that addRoutes is complete
      // set the replace: true, so the navigation will not leave a history record
      next({ ...to, replace: true })
    } catch (error) {
      // remove token and go to login page to re-login
      await store.dispatch('user/resetToken')
      Message.error(error || 'Has Error')
      next(`/login?redirect=${to.path}`)
      NProgress.done()
    }
  }` 这里我将 next({...to,replease : true}) 修改为了 next(to),重新登录,  出现了问题 

微信截图_20190728102616 出现一堆warn 页面无法跳转。 问题点:1.{...to} 未发生错误,to出现了问题。2. replace: true作用 是什么,求大神解答下...

@berber1016
Copy link

berber1016 commented Aug 2, 2019

导航守卫.
解构赋值.

@fenglinhuowu
Copy link

我也遇到这个地方的问题,主要是后端用的不是token,这里需要用token,而且还要调用token获取用户角色,再根据角色去动态生成路由。token卡住了,基本就进行不下去 了。而且不知为什么,
const { roles } = await store.dispatch('user/getInfo') 和
const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
这两个常量无法在控制台打印出来,也不知道有没有获取到数据。
我直接设置成固定的值,结果登录虽然没问题了,但是秒退

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants