router.beforeEach((to, from, next) => { let user_name = localStorage.getItem('user_name') if (to.path === '/') { next() return } else { if (user_name === null || user_name === '') { alert('您暂未登录,请先登录') next('/') } else { next() } } })