router.js 7.2 KB
import Vue from 'vue'
import Router from 'vue-router'
import Index from './pages/index/index.vue'

import tc from '@common/lang/tc.js'
import zh from '@common/lang/zh.js'
import en from '@common/lang/en.js'

Vue.use(Router)

/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return routerPush.call(this, location).catch(error => error)
}

const routes = [

	{
		path: '/',
		name: 'index',
		component: Index,
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/login',
		name: 'login',
		component: () => import('./pages/login/login.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/register',
		name: 'register',
		component: () => import('./pages/register/register.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/password/find',
		name: 'passwordFind',
		component: () => import('./pages/password-find/password-find.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/password/reset',
		name: 'passwordReset',
		component: () => import('./pages/password-reset/password-reset.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/infomation/improve',
		name: 'infomationImprove',
		component: () => import('./pages/infomation-improve/infomation-improve.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/customer/auth',
		name: 'customerAuth',
		component: () => import('./pages/customer-auth/customer-auth.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/profile',
		name: 'profile',
		component: () => import('./pages/profile/profile.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/terms',
		name: 'terms',
		component: () => import('./pages/terms/terms.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/privacy',
		name: 'privacy',
		component: () => import('./pages/privacy/privacy.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/personal/data/collection',
		name: 'personalDataCollection',
		component: () => import('./pages/personal-data-collection/personal-data-collection.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/protocol',
		name: 'protocol',
		component: () => import('./pages/protocol/protocol.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/news/list',
		name: 'newsList',
		component: () => import('./pages/news-list/news-list.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/news/detail',
		name: 'newsDetail',
		component: () => import('./pages/news-detail/news-detail.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},

	{
		path: '/product/introduction',
		name: 'productIntroduction',
		component: () => import('./pages/product-introduction/product-introduction.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},

	{
		path: '/product',
		name: 'product',
		component: () => import('./pages/product/product.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/custom/service',
		name: 'customService',
		component: () => import('./pages/custom-service/custom-service.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/custom/product',
		name: 'customProduct',
		component: () => import('./pages/custom-product/custom-product.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},

	{
		path: '/demo',
		name: 'demo',
		component: () => import('./pages/demo/index.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/about',
		name: 'about',
		component: () => import('./pages/About.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/company/events',
		name: 'companyEvents',
		component: () => import('./pages/company-events/company-events.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/responsibility',
		name: 'responsibility',
		component: () => import('./pages/responsibility/responsibility.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/awards',
		name: 'awards',
		component: () => import('./pages/awards/awards.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/join/us',
		name: 'joinUs',
		component: () => import('./pages/join-us/join-us.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/corporate/culture',
		name: 'corporateCulture',
		component: () => import('./pages/corporate-culture/corporate-culture.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/career/opportunities',
		name: 'careerOpportunities',
		component: () => import('./pages/career-opportunities/career-opportunities.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/help',
		name: 'help',
		component: () => import('./pages/help/help.vue'),
		meta: {
			title: '帮助中心'
		}
	},
	{
		path: '/contact/method',
		name: 'contactMethod',
		component: () => import('./pages/contact-method/contact-method.vue'),
		meta: {
			title: '联系方式'
		}
	},
	{
		path: '/service/net',
		name: 'serviceNet',
		component: () => import('./pages/service-net/service-net.vue'),
		meta: {
			title: '服务网络'
		}
	},
	{
		path: '/map',
		name: 'map',
		component: () => import('./pages/map/map.vue'),
		meta: {
			title: '网站地图'
		}
	},
	{
		path: '/vhis',
		name: 'vhis',
		component: () => import('./pages/vhis/vhis.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/vhis/detail',
		name: 'vhisDetail',
		component: () => import('./pages/vhis-detail/vhis-detail.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},
	{
		path: '/gen/rich',
		name: 'genRich',
		component: () => import('./pages/gen-rich/gen-rich.vue'),
		meta: {
			title: '平安人寿香港'
		}
	},

	{
		path: '/clarms',
		name: 'clarms',
		component: () => import('./pages/clarms/clarms.vue'),
		meta: {
			title: '平安人寿香港'
		}
	}
	// 404页面
	// {
	// 	path: '*', // * 表示上面路径匹配不到的都显示这个页面
	// 	name: '404',
	// 	component: Index
	// },
]

// add route path
routes.forEach(route => {
	route.path = route.path || '/' + (route.name || '');
});

const router = new Router({
	routes,
	// mode: 'history',
});


router.beforeEach((to, from, next) => {
	let langStr = localStorage.getItem("lang") || 'tc';
	let lang;
	// switch
	let defaultTitle = "中国平安人寿(香港)";
	switch (langStr) {
		// 简体
		case "zh":
			lang = zh;
			break;
			// 英文
		case "en":
			defaultTitle = "Ping An Life Hong Kong"
			lang = en;
			break;
			// 繁体
		default:
			defaultTitle = "中國平安人壽(香港)"
			lang = tc;
			break;
	}

	// lang对象为当前语言配置 见 en.js,tc.js,zh.js
	let title = "";
	lang.nav.navList.forEach(e1 => {
		if (e1.path == to.fullPath) {
			title = e1.name;
		} else if (e1.list && e1.list.length > 0) {
			e1.list.forEach(e2 => {
				if (e2.path == to.fullPath) {
					title = e2.name;
				}
			});
		}
	});
	// to参数可以获取要前往页面的信息,包括参数
	title = title || to.meta && to.meta.title;
	if (title) {
		if (title == "平安人寿香港") {
			title = defaultTitle;
		}
		document.title = title;
	}
	// const scrollTopList = [
	// 	"newsList", "newsDetail", "protocol", "privacy", "terms", "paymentType", "reservation"
	// ]
	document.documentElement.scrollTop = 0;
	document.body.scrollTop = 0;
	next();
});

export default router;