import router from './router' import { getAccessToken } from '@/utils/auth' router.beforeEach((to, from, next) => { const needAuth = to.meta.needAuth const token = getAccessToken() if (to.path === '/login' && token !== null) { next({ path: '/' }) } else { next() } if (needAuth && token === null) { next('/login') } else { next() } if (!needAuth) { next() } else { if (token === null) { next('/login') } } })