import { getKeyToken } from "@/auth/auth"; import { isNil } from "lodash-es"; import Vue from "vue"; import Router from "vue-router"; import Home from "../views/Home.vue"; Vue.use(Router); // function propsValidator(route, component) { // const props = { ...route.params }; // Object.entries(props).map(([key, prop]) => { // console.log(prop, key); // if (!(prop instanceof component.props[key].type)) { // props[key] = component.props[key].type(prop); // } // }); // return props; // } let router = new Router({ mode: "history", base: process.env.BASE_URL, routes: [ { path: "/", name: "home", component: Home, }, { path: "/about", name: "about", // route level code-splitting // this generates a separate chunk (about.[hash].js) for this route // which is lazy-loaded when the route is visited. component: () => import(/* webpackChunkName: "about" */ "../views/About.vue"), }, // { // path: "/xxx/:id", // component: XXX, // props(route) { // return propsValidator(route, XXX); // } // } ], }); router.beforeEach((to, from, next) => { const [uid, token] = getKeyToken(); if ((isNil(uid) || isNil(token)) && to.path.includes("/login") === false) { if ( window.___lastInvalidDate === undefined || window.___lastInvalidDate < Date.now() - 300 ) { window.___lastInvalidDate = Date.now(); } router.push("/login"); next(false); } else { next(); } }); export default router;