| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import type { RouteRecordRaw } from 'vue-router'
- import { createRouter, createWebHistory } from 'vue-router'
- import { useAppStore } from '@/stores/app'
- import Login from '@/pages/common/login.vue'
- import Layout from '@/layouts/Layout.vue'
- export const asyncRoutes: RouteRecordRaw[] = [
- {
- name: 'category',
- path: 'category',
- component: () => import('@/pages/category/index.vue'),
- meta: {
- title: '分类管理',
- icon: 'system-3'
- }
- },
- {
- name: 'article',
- path: 'article',
- component: () => import('@/pages/article/index.vue'),
- meta: {
- title: '咨询管理',
- icon: 'collection'
- }
- },
- {
- name: 'carousal',
- path: 'carousal',
- component: () => import('@/pages/carousal/index.vue'),
- meta: {
- title: '轮播图管理',
- icon: 'image'
- }
- },
- {
- name: 'product',
- path: 'product',
- meta: {
- title: '产品管理',
- icon: 'shop'
- },
- component: () => import('@/pages/product/index.vue')
- },
- {
- name: 'pet-variety',
- path: 'pet-variety',
- meta: {
- title: '宠物品种',
- icon: 'cat'
- },
- component: () => import('@/pages/pet-variety/index.vue')
- }
- ]
- const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes: [
- {
- name: 'layout',
- component: Layout,
- path: '/',
- redirect: {
- name: 'category'
- },
- children: asyncRoutes
- },
- {
- name: 'login',
- path: '/login',
- component: Login
- }
- ]
- })
- router.beforeEach((to, from, next) => {
- if (to.name !== 'login') {
- const appStore = useAppStore()
- appStore.isLogin ? next() : next({ name: 'login' })
- return
- }
- next()
- })
- export default router
|