2 Star 0 Fork 0

Manson / HG

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
router.js 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
Manson 提交于 2022-05-11 10:40 . 仓库
import {
RouterMount,
createRouter,
runtimeQuit
} from './js_sdk/uni-simple-router';
import {
BACK_URL
} from './config/cachekey'
import store from './store'
import {
silentLogin
} from '@/api/app'
import {
getWxCode
} from './utils/login'
import Cache from './utils/cache'
import wechath5 from './utils/wechath5'
import {isWeixinClient} from './utils/tools'
const scrollInfo = {};
let first = null;
const whiteList = ['register', 'login', 'forget_pwd']
const router = createRouter({
platform: process.env.VUE_APP_PLATFORM,
APP: {
animation: {}
},
h5: {
scrollBehavior: (to, from, savedPosition) => {
const XY = scrollInfo[to.name];
if (XY) return XY;
return {
x: 0,
y: 0
};
}
},
routerErrorEach: ({
type,
msg
}) => {
router.$lockStatus = false;
// #ifdef APP-PLUS
if (type === 3) {
runtimeQuit();
}
// #endif
},
debugger: false,
routes: [
...ROUTES,
{
path: '*',
redirect: (to) => {
return {
name: '404'
}
}
},
]
});
console.log(router)
let count = 0;
router.beforeEach((to, from, next) => {
// #ifdef H5
// tab页面的滚动缓存
if (from.meta.keepScroll === true) {
scrollInfo[from.name] = {
x: window.scrollX,
y: window.scrollY
}
}
// #endif
console.log(to,from, 'beforeEach---开始跳转')
let index = whiteList.findIndex((item) => from.path.includes(item))
if (index == -1 && !store.getters.token) {
Cache.set(BACK_URL, from.fullPath)
}
if (to.meta.auth && !store.getters.token) {
next('/pages/login/login');
return
} else {
next()
}
});
router.afterEach( (to, from, next) => {
// #ifdef H5
// 添加定时器防止拿到的域名是上一个域名
setTimeout(async () => {
if (isWeixinClient()) {
// jssdk配置
await wechath5.config()
// 分享配置
if (to.path.includes('goods_details')) return
store.dispatch('wxShare')
}
})
// #endif
});
export {
router,
RouterMount
}
1
https://gitee.com/liaomingxuan/hg.git
git@gitee.com:liaomingxuan/hg.git
liaomingxuan
hg
HG
master

搜索帮助