router.js 849 B

12345678910111213141516171819202122232425262728
  1. import { isCtrlPress } from '@/utils/keyboard'
  2. export default ({ app, store, redirect, $cookies }) => {
  3. app.router.beforeEach((to, from, next) => {
  4. // 在每次路由跳转的时候进行判断
  5. if (isCtrlPress()) {
  6. // 若是 ctrl 按键被按下,则以新窗口打开目标页面
  7. window.open(to.fullPath)
  8. // 并阻止当前页面的跳转
  9. return next(false)
  10. }
  11. let token = ''
  12. // console.log($cookies.get('can-use-cookie'), 'can use cookie')
  13. // console.log($cookies.get('token'), 'token')
  14. if ($cookies.get('can-use-cookie')) {
  15. token = $cookies.get('token')
  16. }
  17. if (token) {
  18. // console.log('set status')
  19. store.commit('setUserInfo', $cookies.get('user-info'))
  20. } else {
  21. // console.log('remove status')
  22. store.commit('clearUserInfo')
  23. }
  24. next()
  25. })
  26. }