logic-helper
Version:
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
60 lines (56 loc) • 1.9 kB
JavaScript
import * as VueRouter from "vue-router";
import { store } from '@/common/js/app.js'
import {defineAsyncComponent} from "vue"
import deepEqual from 'deep-equal';
import TopoChart from "../pages/TopoChart.vue"
const routes = [{
path: "/topo/:file/:name",
component: TopoChart,
meta: {
pageBox: defineAsyncComponent(() => import('../layout/ChartBox.vue')),
},
name: 'editor'
},
{
path: "/list",
component: defineAsyncComponent(() => import('../pages/TopoList.vue')),
meta: {
pageBox: defineAsyncComponent(() => import('../layout/ListBox.vue')),
},
name:'list'
},{
path: "/test",
component: defineAsyncComponent(() => import('../pages/TopoTest.vue')),
meta: {
pageBox: defineAsyncComponent(() => import('../layout/ListBox.vue')),
}
},
{
path: "/",
redirect: "/list"
},
];
const router = VueRouter.createRouter({
// 4. Provide the history implementation to use. We are using the hash history for simplicity here.
history: VueRouter.createWebHashHistory(),
routes, // short for `routes: routes`
});
const isDev = process.env.NODE_ENV === 'development';
router.beforeEach((to, from, next) => {
if (from.matched[0]&&from.matched[0].path == "/topo/:file/:name") {//离开编辑器页
store.controller.setMode('info')
} else if (to.matched[0]&&to.matched[0].path == "/topo/:file/:name"&&from.path=='/'&&!/\/[0-9]{13}$/.test(to.query.code)&&!sessionStorage.getItem(to.query.code + '_logined')) {//首次进入编辑器页
store.controller.setMode('test')
sessionStorage.setItem(to.query.code + '_logined', '1')
}
if(from.query.code&&from.query.code!=to.query.code){
to.query.code = from.query.code;
return next(to);
} else if(!to.query.code){
store.controller.setMode('info')
to.query.code = Date.now();
return next(to);
}
next();
});
export default router;