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.

36 lines
730 B
JavaScript

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