Newer
Older
KaiFengPC / src / router / index.js
@zhangdeliang zhangdeliang on 20 May 1 KB 项目初始化
import { createWebHashHistory, createRouter } from 'vue-router';
/* Layout */
import Layout from '@/layout';

// 公共路由
export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login'),
    hidden: true,
  },
  {
    path: '/',
    component: () => import('@/views/login'),
    hidden: true,
  },
  // 无路由时跳转404
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404'),
    hidden: true,
  },
  // 401无权限
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true,
  },
  // 首页
  {
    path: '/index',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '',
        component: () => import('@/views/index'),
        name: '首页',
        meta: { title: '首页', icon: 'dashboard', affix: true, noCache: true },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

export default router;