import modeMap from '~/configs/mode-map' import axios from 'axios' const whiteList = ['/auth'] export default function ({ route, error, redirect }) { if (whiteList.indexOf(route.path) > -1) return const authUserId = parseInt(route.params.template) const auth = modeMap.find((item) => item.authUserId === authUserId) let routePrefix = !auth ? `/${authUserId}/app` : `/${authUserId}/${auth.mode}` const baseURL = process.env.BASE_URL + '/wx/auth/shop/info' console.log(auth && auth.mode, authUserId) return axios .get(baseURL, { params: { authUserId: authUserId }, }) .then(({ data }) => { if (data.code === -1) { error({ statusCode: 404, message: '页面不存在', }) } else if (authUserId === 12 && auth.mode === 'ross' && route.path.indexOf(`${authUserId}/app`) > -1) { // console.log(route.fullPath.replace(`${authUserId}/app`, `${authUserId}/ross`)) redirect(route.fullPath.replace(`${authUserId}/app`, `${authUserId}/ross`)) } else if (route.path.indexOf(routePrefix) !== 0) { error({ statusCode: 404, message: '页面不存在', }) } }) .catch(() => { error({ statusCode: 404, message: '页面不存在', }) }) }