登录拦截代码
const whiteList = [
'/pages/login/login'
];
const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab'];
/**
* 是否允许访问
* @param url
* @returns {boolean}
*/
const hasPermission = (url) => {
if (whiteList.indexOf(url) > -1 || Store.getters.token) {
return true;
}
return false;
}
list.forEach(item => {
uni.addInterceptor(item, {
invoke: (e) => {
console.log('陆游路径', e);
if (!hasPermission(e.url)) {
// 将用户的目标路径保存下来
// 这样可以实现 用户登录之后,直接跳转到目标页面
uni.setStorageSync("URL", e.url)
uni.navigateTo({
url: "/pages/login/login",
success: res => {
uni.hideTabBar();
}
});
return false;
}
return true;
}
});
});
pages.json设置如下:
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarBackgroundColor": "#006dfe",
"navigationBarTextStyle": "white",
"navigationBarTitleText": "首页",
"enablePullDownRefresh": false
}
},
{
"path": "pages/user/user",
"style": {
"navigationBarTitleText": "我的",
"navigationBarBackgroundColor": "#006dfe",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": false
}
},
{
"path": "pages/login/login",
"style": {
"navigationBarTitleText": "登录",
"navigationBarBackgroundColor": "#006dfe",
"navigationBarTextStyle": "white",
"navigationStyle": "custom",
"enablePullDownRefresh": false
}
}
]
helloheil (作者)
hideTabBar:fail not TabBar page
这个hideTabBar只能在tabBar页面使用qvq
关键是重定向到login页面的时候tabbar他又不自己隐藏,无解吗?
2022-12-13 11:07
2***@qq.com
回复 helloheil: 您好 请问您是怎么解决的
2024-04-19 12:57