uni-starter,tabBar跳转,判断是否登录失效

问题描述:使用uni-starter组件后,在pages.json中配置了uniIdRouter,发下tabBar之间跳转失效

原因:查看文档发现有一句话【uniIdRouter底层使用navigateTo、redirectTo、reLaunch、switchTab的拦截器进行页面跳转拦截,不会拦截进入首页和点击原生tabbar。】

解决:取store.hasLogin中的登录状态,判断是否登录,没有登录就跳转到登录页面

<template>
	<view class="page">
	</view>
</template>

<script>
	import {store} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		data() {
			return {
			}
		},
		onShow() {
		   if(!store.hasLogin){
				uni.redirectTo({
					url: '/uni_modules/uni-id-pages/pages/login/login-withoutpwd',
				});
		   }
		},
		methods: {
		}
	}
</script>

猜你喜欢

转载自blog.csdn.net/weixin_40841731/article/details/130122178