You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
869 B
JavaScript

8 months ago
import uniCrazyRouter from "uni-crazy-router";
export function setupRouter (app) {
// 接收vue3的实例并注册uni-crazy-router
app.use(uniCrazyRouter)
}
const whiteList = ['pages/login/login'];
// const whiteList = [];
8 months ago
uniCrazyRouter.beforeEach(async (to, from ,next)=>{
console.log('beforEach router')
const path = to.url;
const uInfo = uni.getStorageSync('uInfo') || null;
8 months ago
if (whiteList.includes(path)) {
next();
return;
}
if (uInfo) {
next();
8 months ago
return;
}
uniCrazyRouter.afterNotNext(() => {
uni.navigateTo({url: '/pages/login/login'})
// if (uInfo) {
// uni.navigateTo({url: '/pages/index/index'})
// } else {
// uni.navigateTo({url: '/pages/login/login'})
// }
8 months ago
})
})
uniCrazyRouter.afterEach((to, from)=>{
console.log('afterEach router')
// 逻辑代码
})
uniCrazyRouter['on'+'Error']((to, from)=>{
})