123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import { createRouter, createWebHistory } from "vue-router";
- const isMobile = /Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(navigator.userAgent);
- const redirectPath = isMobile ? "/m_home" : "/p_home";
- const routes = [{
- path: "/",
- redirect: redirectPath,
- },
- {
- path: "/m_home",
- name: "M_Home",
- component: () =>
- import ("@/views/mobile/home/Home.vue"),
- meta: {
- title: "首页",
- isNav: true,
- type: "mobile",
- },
- },
- {
- path: "/m_industry-park",
- name: "M_IndustryPark",
- component: () =>
- import ("@/views/mobile/industry/IndustryPark.vue"),
- meta: {
- title: "产业园区",
- isNav: true,
- type: "mobile",
- },
- },
- {
- path: "/m_investment-projects",
- name: "M_InvestmentProjects",
- component: () =>
- import ("@/views/mobile/project/InvestmentProjects.vue"),
- meta: {
- title: "招商项目 ",
- isNav: true,
- type: "mobile",
- },
- },
- {
- path: "/m_preferential-policy",
- name: "M_PreferentialPolicy",
- component: () =>
- import ("@/views/mobile/policy/PreferentialPolicy.vue"),
- meta: {
- title: "优惠政策",
- isNav: true,
- type: "mobile",
- },
- },
- {
- path: "/m_preferential-policy-detail",
- name: "M_PreferentialPolicyDetail",
- component: () =>
- import ("@/views/mobile/policy/PreferentialPolicyDetail.vue"),
- meta: {
- title: "优惠政策",
- type: "mobile",
- },
- },
- {
- path: "/m_about-me",
- name: "M_AboutMe",
- component: () =>
- import ("@/views/mobile/aboutMe/AboutMe.vue"),
- meta: {
- title: "关于书院",
- isNav: true,
- type: "mobile",
- },
- },
- {
- path: "/m_apply-for-entry",
- name: "M_ApplyForEntry",
- component: () =>
- import ("@/views/mobile/ApplyForEntry.vue"),
- meta: {
- title: "申请入驻",
- isNav: true,
- type: "mobile",
- },
- },
- {
- path: "/p_home",
- name: "P_Home",
- component: () =>
- import ("@/views/pc/home/Home.vue"),
- meta: {
- title: "首页",
- isNav: true,
- type: "pc",
- },
- },
- {
- path: "/p_industry-park",
- name: "P_IndustryPark",
- component: () =>
- import ("@/views/pc/industry/IndustryPark.vue"),
- meta: {
- title: "产业园区",
- isNav: true,
- type: "pc",
- },
- },
- {
- path: "/p_investment-projects",
- name: "P_InvestmentProjects",
- component: () =>
- import ("@/views/pc/project/InvestmentProjects.vue"),
- meta: {
- title: "招商项目 ",
- isNav: true,
- type: "pc",
- },
- },
- {
- path: "/p_preferential-policy",
- name: "P_PreferentialPolicy",
- component: () =>
- import ("@/views/pc/policy/PreferentialPolicy.vue"),
- meta: {
- title: "优惠政策",
- isNav: true,
- type: "pc",
- },
- },
- {
- path: "/p_preferential-policy-detail",
- name: "P_PreferentialPolicyDetail",
- component: () =>
- import ("@/views/pc/policy/PreferentialPolicyDetail.vue"),
- meta: {
- title: "优惠政策",
- type: "pc",
- },
- },
- {
- path: "/p_about-me",
- name: "P_AboutMe",
- component: () =>
- import ("@/views/pc/aboutMe/AboutMe.vue"),
- meta: {
- title: "关于书院",
- isNav: true,
- type: "pc",
- },
- },
- {
- path: "/p_apply-for-entry",
- name: "P_ApplyForEntry",
- component: () =>
- import ("@/views/pc/apply/ApplyForEntry.vue"),
- meta: {
- title: "申请入驻",
- isNav: true,
- type: "pc",
- },
- },
- ];
-
- const router = createRouter({
- history: createWebHistory("/public"),
- routes,
- scrollBehavior() {
- return {
- left: 0,
- top: 0,
- };
- },
- });
- router.beforeEach((to, from, next) => {
- // 移动端访问PC
- if (isMobile && to.meta.type !== "mobile") {
- let routers = router.options.routes.filter(v => v.path != "/" && v.meta.type === "mobile");
- let path = null;
- routers.forEach(v => {
- if (v.name.split("_")[1] == to.name.split("_")[1]) {
- path = v.path;
- }
- });
-
- if (path) next(path);
- next("/");
- }
- // pc 访问 移动
- if (!isMobile && to.meta.type !== "pc") {
- const routers = router.options.routes.filter(v => v.path != "/" && v.meta.type === "pc");
- let path = null;
- routers.forEach(v => {
- if (v.name.split("_")[1] == to.name.split("_")[1]) {
- path = v.path;
- }
- });
- if (path) next(path);
- next("/");
- }
- next();
- });
- export default router;
|