index.js 1.17 KB
import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Dashboard',
    component: () => import('@/views/Dashboard.vue')
  },
  {
    path: '/login',
    name: 'LoginPage',
    component: () => import (
      '../views/Login.vue'
    )
  },
  {
    path: "/404",
    name: "notFound",
    component: () => import('@/views/notFound.vue')
  },
  // {
  //   path: '/:pathMatch(.*)*',
  //   redirect: '/404'
  // }
]


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

const childRoute = ['/system'];
const isChildRoute = path => childRoute.some(item => path.startsWith(item));
// const rawAppendChild = HTMLHeadElement.prototype.appendChild;
// const rawAddEventListener = window.addEventListener;
router.beforeEach((to, from, next) => {
  console.log(from)
  // if (to.meta.title) {
  //   document.title = to.meta.title;
  // }
  // next();
  // 从子项目跳转到主项目
  // if(isChildRoute(from.path) && !isChildRoute(to.path)){
  //   HTMLHeadElement.prototype.appendChild = rawAppendChild;
  //   window.addEventListener = rawAddEventListener;
  // }
  //next();
});

export default router