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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
if (whiteList.includes(path) || uInfo) {
next()
return;
}
uniCrazyRouter.afterNotNext(() => {
// 拦截路由,并且跳转去登录页
uni.navigateTo({
url: '/pages/login/login'
})
})
})
uniCrazyRouter.afterEach((to, from)=>{
console.log('afterEach router')
// 逻辑代码
})
uniCrazyRouter['on'+'Error']((to, from)=>{
})