当前位置:网站首页>微信小程序的路由拦截
微信小程序的路由拦截
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;
边栏推荐
猜你喜欢

新型电信“套路”,我爸中招了!

智能垃圾桶(八)——红外对管传感器(树莓派pico)

go基础部分学习笔记记录

A common method and the use of selenium

Unity 之 音频类型和编码格式介绍

IP协议从0到1

MySQL---operator

Combinatorics Notes (6) Associative Algebra of Locally Finite Partially Ordered Sets, Möbius Inversion Formula

AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)

go mode tidy出现报错go warning “all“ matched no packages
随机推荐
go mode tidy出现报错go warning “all“ matched no packages
Go record - slice
MySQL---基本的select语句
ThreadLocal
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
【AcWing】第 62 场周赛 【2022.07.30】
京东获取商品历史价格信息 API
Huawei's top engineers lasted nine years "anecdotal stories network protocol" PDF document summary, is too strong
GateWay实现负载均衡
【pytorch】pytorch 自动求导、 Tensor 与 Autograd
Flutter gets the height of the status bar statusbar
API for JD.com to obtain historical price information of commodities
新型电信“套路”,我爸中招了!
宁波大学NBU IT项目管理期末考试知识点整理
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none 失败
MySQL---operator
How to install CV2 smoothly in Anaconda
基于WPF重复造轮子,写一款数据库文档管理工具(一)
UVM RAL模型和内置seq
无主复制系统(1)-节点故障时写DB