123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // //创建一个路由器
- import { createRouter, createWebHashHistory,createWebHistory } from "vue-router";
- import configurator from "@/view/configurator.vue"
- import resultLeft from '@/view/result/resultLeft.vue';
- import resultRight from '@/view/result/resultRight.vue';
- const home = () => import("@/views/home/index.vue")
- import result from '@/view/result.vue';
- import { get } from "js-cookie";
- import { getToken2,setToken,setUserId } from "../utils/token";
- const router = createRouter({
- history: createWebHashHistory(),
- // history: createWebHistory(),
- routes: [
- {
- path: '/configurator',
- name:'模型库',
- component: configurator,// 这是路由的籁加载,也可以其他方式
- beforeEnter: (to, from,next) => {
- console.log(to, from);
- next()
- },
-
- },
- {
- path: '/vtk',
- name:'案例',
- component: () => import('@/view/vtk/vtk.vue'),// 这是路由的籁加载,也可以其他方式
-
- },
- {
- path: '/vtk2',
- name:'案例1',
- component: () => import('@/view/vtk/vtk2.vue'),// 这是路由的籁加载,也可以其他方式
-
- },
- {
- path: '/demo',
- name:'案例3',
- component: () => import('@/view/vtk/demo.vue'),// 这是路由的籁加载,也可以其他方式
-
- },
- // {
- // path: '/',
- // name:'首页',
- // component: () => import('@/view/home.vue'),
- // meta:{
- // keepAlive:false, // 需要缓存
- // title: '首页'
- // }
- // },
-
- {
- path: '/login',
- name: 'login',
- component: () => import('@/view/login.vue'), // 登录页面组件
- },
- {
- path: '/',
- name:'煤矿灾害态势推演',
- component: () => import('@/view/appmian.vue'),
- meta:{
- keepAlive:false, // 需要缓存
- title: '煤矿灾害态势推演'
- },
- children:[
- {
- path: '/home',
- name: 'home',
- component: () => import('@/views/home/index.vue'),
- }
- ]
-
- },
- // {
- // path: "/home",
- // name: "home",
- // component: home
- // },
- // {
- // path: '/home',
- // name:'局部',
- // component: () => import( "@/views/home/index.vue"),
- // meta:{
- // keepAlive:false, // 需要缓存
- // title: '局部'
- // },
-
- // },
- {
- path: '/goods',
- name: 'goods',
- component: {
- // 这里的 goods 对应 router-view 中的 name
- goods: resultLeft
- }
- },
- {
- path: '/orderinfo',
- name: 'orderinfo',
- component: {
- // 这里的 orderinfo 对应 router-view 中的 name
- orderinfo:resultRight
- }
- }
-
- // {
- // path: '/resultLeft',
- // name:'resultLeft',
- // component: resultLeft,// 这是路由的籁加载,也可以其他方式
- // },
- // {
- // path: '/resultRight',
- // name:'resultRight',
- // components:{
- // resultRight:resultRight
- // } // 这是路由的籁加载,也可以其他方式
- // },
-
- ]
- })
- //修改动态网页标题 beforeEach 导航钩子,路由改变前触发
- router.beforeEach((to,from,next) =>{
- //window.document.title = to.meta.title;
- // const urlParams = new URLSearchParams(to.fullPath);
- // const aids = urlParams.get('aid');
-
- let token = getToken2();
- console.log('守卫中Token:', token);
- if(to.fullPath.indexOf("aid")>0){
- setToken('e47b87eec69545559d1e81e56626da68');
- setUserId('5f06c8bc77234f969d13e160b54c27e3');
- console.log('守卫中aids:', to.fullPath);
- window.document.title = to.name;
- next();
- }else if (!token && to.name !== 'login') {
- // 如果没有 token 并且目标不是登录页,则重定向到登录页
- next({ name: 'login' });
- } else {
- window.document.title = to.name;
- next();
- }
-
- })
- router.afterEach((to,from,next) =>{
- window.scrollTo(0,0);
- })
- export default router;
|