// router.js
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
{
path: '/',
component: require('./views/Home'),
meta: {
requiresAuth: true
}
},
]

const router = new VueRouter({
routes: routes
})

router.beforeEach((to, from, next) => {
let token = window.localStorage.getItem('token')
if (to.matched.some(record => record.meta.requiresAuth) && (!token || token === null)) {
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
})

export default router

<script>
// App.vue
export default {
watch:{
'$route':function(to,from){
let token = window.localStorage.getItem('token');
         if (to.matched.some(record => record.meta.requiresAuth) && (!token || token === null)) {
           next({
           path: '/login',
           query: { redirect: to.fullPath }
           })
         } else {
       next()
         }
   }
  }
}
</script>

最新文章

  1. 解决Maven工程中报 Missing artifact jdk.tools:jdk.tools:
  2. 百度编辑器UEditor常用设置函数大全
  3. 调试 zeromq 发现 accept 死循环
  4. guzzle调用失败-缺少guzzle
  5. HTML5 模拟现实物理效果,感受 Web 技术魅力
  6. oracle 空间数据库说明
  7. IOS中用UIStoryBoard类初始化/跳转控制器
  8. 又爱又恨的BOOTSTRAP
  9. hdu 4608 I-number 大整数
  10. NSAttributedString in Swift
  11. Python开发【字符串格式化篇】
  12. Taro之使用百度地图
  13. jmeter性能测试入门
  14. [Mockito] Spring Unit Testing with Mockito
  15. mvc 前端校验
  16. 下载安装windows版Redis
  17. 2019.01.21 洛谷P3919 【模板】可持久化数组(主席树)
  18. Lerning Entity Framework 6 ------ Defining Relationships
  19. 【LibreOJ】#6392. 「THUPC2018」密码学第三次小作业 / Rsa 扩展欧几里得算法
  20. 哈,今天终于在电脑上吧oracle给装上了

热门文章

  1. leetcode 813. Largest Sum of Averages
  2. windows 查看端口是否被占用
  3. Django_ORM字段_字段参数
  4. SDL2.0.9源码分析
  5. MySQL Execution Plan--IN子查询包含超多值引发的查询异常
  6. edgedb 内部pg 数据存储的探索 (五) 运行进程列表信息
  7. DOM 基础
  8. Python 反射(reflection)
  9. 深度系统 deepin 15.9 关闭桌面
  10. day62 中间件