liuxiaolong
2019-05-06 2ab7a76a38fbf8fa107bf6371f5410ba54e1d394
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Vue from 'vue'
import Router from 'vue-router'
import Meta from 'vue-meta'
 
import globals from '@/globals'
 
// Layouts
import Layout from '@/layout/LayoutHorizontalUNSidenav'
// import Layout from '@/layout/Layout3'
 
Vue.use(Router)
Vue.use(Meta)
 
const router = new Router({
  base: '/',
  routes: [
    {
      path: '/login',
      name: 'login',
      component: () => import('@/pages/Login/Login')
    },
    {
      path: '/',
      component: Layout,
      meta: {
        // 添加该字段,表示进入这个路由是需要登录的
        requireAuth: true
      },
      children: [
        {
          path: '',
          name: 'home',
          component: () =>
            import('@/pages/Analysis'),
          meta: {
            requireAuth: true
          }
        }
      ]
    },
    {
      path: '/401',
      component: () => import('@/pages/Error/401.vue')
    },
    {
      path: '*',
      component: () => import('@/pages/Error/404.vue')
    }
  ]
})
 
router.afterEach(() => {
  // 主页动画
  const splashScreen = document.querySelector('.app-splash-screen')
  if (splashScreen) {
    splashScreen.style.opacity = 0
    setTimeout(
      () =>
        splashScreen &&
        splashScreen.parentNode &&
        splashScreen.parentNode.removeChild(splashScreen),
      300
    )
  }
  // On small screens collapse sidenav
  if (
    window.layoutHelpers &&
    window.layoutHelpers.isSmallScreen() &&
    !window.layoutHelpers.isCollapsed()
  ) {
    setTimeout(() => window.layoutHelpers.setCollapsed(true, true), 10)
  }
 
  // Scroll to top of the page
  globals().scrollTop(0, 0)
})
 
router.beforeEach((to, from, next) => {
  // Set loading state
  document.body.classList.add('app-loading')
 
  // Add tiny timeout to finish page transition
  setTimeout(() => next(), 10)
})
 
export default router