当前位置:网站首页>微信小程序的路由拦截
微信小程序的路由拦截
2022-07-31 17:42:00 【程序猿向前跑】
直接上代码
我们知道vue可以拦截路由,微信小程序则需要我们自己进行路由拦截器的验证
// utils/filter.js
function loginCheck(pageObj) {
if (pageObj.onLoad) {
let _onLoad = pageObj.onLoad;
// 使用onLoad的话需要传递options
pageObj.onLoad = function (options) {
if(wx.getStorageSync('USERID')) {
// 获取当前页面
let currentInstance = getPageInstance();
_onLoad.call(currentInstance, options);
} else {
//跳转到登录页
wx.redirectTo({
url: "/pages/login/login"
});
}
}
}
return pageObj;
}
// 获取当前页面
function getPageInstance() {
var pages = getCurrentPages();
return pages[pages.length - 1];
}
exports.loginCheck = loginCheck;
边栏推荐
猜你喜欢

This 985 professor is on fire!After 10 years of Ph.D. supervisor, no one has graduated with a Ph.D.!

动态规划(一)

adb shell error error: device unauthorized

Intelligent bin (9) - vibration sensor (raspberries pie pico implementation)

MySQL---单行函数

研发过程中的文档管理与工具

ThreadLocal

架构师04-应用服务间加密设计和实践

华为顶级工程师历时9年总结的“趣谈网络协议”PDF文档,太强了

关于柱状图的经典画法总结
随机推荐
After Effects 教程,如何在 After Effects 中调整过度曝光的快照?
Apache EventMesh 分布式事件驱动多运行时
Flutter set the background color of the statusbar status bar and APP method (AppBar) internal consistent color.
MySQL---单行函数
基于WPF重复造轮子,写一款数据库文档管理工具(一)
多数据中心操作和检测并发写入
Kotlin coroutines: continuation, continuation interceptor, scheduler
组合学笔记(六)局部有限偏序集的关联代数,Möbius反演公式
浅谈网络安全之算法安全
九齐ny3p系列语音芯片替代国产方案KT148A性价比更高420秒长度
Chinese encoding Settings and action methods return values
认识异常 (看完这篇你就懂了)
21.支持向量机—核函数的介绍
获取抖音视频详情 API
【源码解析】BeanFactory和FactoryBean
adb shell error error: device unauthorized
Intelligent bin (9) - vibration sensor (raspberries pie pico implementation)
Masterless replication system (2) - read and write quorum
flutter设置statusbar状态栏的背景颜色和 APP(AppBar)内部颜色一致方法。
How to install CV2 smoothly in Anaconda