permission.js 390 B

1234567891011121314151617181920
  1. import router from './router'
  2. import { getAccessToken } from '@/utils/auth'
  3. router.beforeEach((to, from, next) => {
  4. const needAuth = to.meta.needAuth
  5. const token = getAccessToken()
  6. if (token != null) {
  7. if (to.path === '/login') {
  8. next({ path: '/' })
  9. } else {
  10. next()
  11. }
  12. } else {
  13. if (needAuth) {
  14. next('/login')
  15. } else {
  16. next()
  17. }
  18. }
  19. })