当前位置:网站首页>微信小程序的路由拦截
微信小程序的路由拦截
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;
边栏推荐
- Flutter set the background color of the statusbar status bar and APP method (AppBar) internal consistent color.
- JD.com searches for products by keyword API
- 浅谈网络安全之算法安全
- MySQL---operator
- 认识异常 (看完这篇你就懂了)
- Automated testing - web automation - first acquaintance with selenium
- MySQL---创建和管理数据库和数据表
- 【源码解析】BeanFactory和FactoryBean
- Handling Write Conflicts under Multi-Master Replication (1)-Synchronous and Asynchronous Conflict Detection and Conflict Avoidance
- 联邦学习:联邦场景下的多源知识图谱嵌入
猜你喜欢

【码蹄集新手村600题】不通过字符数组来合并俩个数字

这位985教授火了!当了10年博导,竟无一博士毕业!

IP protocol from 0 to 1

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

MySQL---多表查询

adb shell error error: device unauthorized

21.支持向量机—核函数的介绍

Automated testing - web automation - first acquaintance with selenium

学生管理系统第一天:完成登录退出操作逻辑 PyQt5 + MySQL5.8

Introduction of Jerry voice chip ic toy chip ic_AD14NAD15N full series development
随机推荐
【Yugong Series】July 2022 Go Teaching Course 020-Array of Go Containers
无主复制系统(3)-Quorum一致性的局限性
常用的安全渗透测试工具(渗透测试工具)
MySQL---子查询
Masterless Replication System (3)-Limitations of Quorum Consistency
IP协议从0到1
Huawei mobile phone one-click to open "maintenance mode" to hide all data and make mobile phone privacy more secure
GateWay实现负载均衡
Masterless replication system (2) - read and write quorum
Multi-datacenter operation and detection of concurrent writes
MySQL - single function
go mode tidy出现报错go warning “all“ matched no packages
This 985 professor is on fire!After 10 years of Ph.D. supervisor, no one has graduated with a Ph.D.!
研发过程中的文档管理与工具
Anaconda如何顺利安装CV2
Last write wins (discards concurrent writes)
无主复制系统(2)-读写quorum
【网络通信三】研华网关Modbus服务设置
Mariabackup实现Mariadb 10.3的增量数据备份
Kotlin coroutines: continuation, continuation interceptor, scheduler