text: import Vue from 'vue'
  import VueRouter from 'vue-router'
  
  const Login = () => import('@/pages/Login')
  const Main = () => import('@/pages/Main.vue')
  const Welcome = () => import('@/pages/Welcome')
  const Category = () => import('@/pages/Category')
  const Product = () => import('@/pages/Product')
  const Ad = () => import('@/pages/Ad')
  const AdminUser = () => import('@/pages/AdminUser')
  
  Vue.use(VueRouter)
  
  const routes = [
    { path: '/login', component: Login, meta: { isPublic: true } },
    {
      path: '/',
      component: Main,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/category', component: Category },
        { path: '/product', component: Product },
        { path: '/ad', component: Ad },
        { path: '/admin_user', component: AdminUser }
      ]
    }
  ]
  
  const router = new VueRouter({
    routes
  })
  
  // 挂载路由导航守卫
  router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token')
  
    if (!to.meta.isPublic && !token) return next('/login')
    next()
  })
  
  export default router
  