小程序怎么动态修改默认的启动页?

小程序 文章 2020-08-24 21:21 1640 0 全屏看文

AI助手支持GPT4.0

小程序怎么动态修改默认的启动页?How to dynamically modify the default startup page of the applet?

小程序怎么动态修改默认的启动页?

目前遇到了一种业务场景:

1、小程序的默认启动页,设置为页面A,当用户没有登录时,进入页面A,因为此时没有token,后端会返回403,前端会自动重定向到登录页

2、用户从登录页登录后,后端会返回当前用户的角色信息,前端会把角色信息存储在小程序的storage缓存里

3、如果是角色a,则跳转到页面A;如果是角色b,则跳转到页面B

如果是上面的正常流程,逻辑是没问题的,但是如果用户当前角色是b,然后进入到页面B后,进行一些操作后,把小程序切换到后台,再此进入时,小程序又会重新打开默认的启动页A,而此时其实用户是没有页面A的权限的,因为只有角色a才能访问页面A

我目前对这个问题的处理方案是在页面A进入时就用缓存里的角色信息进行判断,如果是角色a就不做处理,如果是角色b就重定向到B页面去,可是感觉这样处理很麻烦,也不规范,那么能不能动态的设置小程序的默认启动页呢,可是app.json貌似是不能动态修改的,这种问题有没有比较优雅的解决方案呢?

我能想到的另外一种方案,就是单独做一个空白的启动页C作为默认页,在这个C页面去判断用户角色,然后跳转到对应页面,但是这样也会有一个重定向的过程,体验和第一种办法差不多,有更好的办法吗?

At present, we have encountered a business scenario: 1. The default startup page of the applet is set to page A. when the user does not log in, he will enter page A. because there is no token at this time, the back-end will return 403, and the front-end will automatically redirect to the login page 2. After the user logs in from the login page, the back-end will return the current user's role information, and the front-end will store the role information in the storage cache of the applet. 3. If it is role a, it will jump to page a; if it is role B, it will jump to page B If it is the normal process above, the logic is OK, but if the user's current role is B, and then enter page B, after some operations, switch the applet to the background. When entering again, the applet will reopen the default startup page A. at this time, the utility user does not have the permission of page a, because only role a can access page a My current solution to this problem is to use the role information in the cache to judge when page a enters. If it is role a, it will not be processed. If it is role B, it will be redirected to page B. However, it is very troublesome and nonstandard to handle this problem. Can you dynamically set the default startup page of the applet app.json It seems that it can't be modified dynamically Are there any elegant solutions to these problems? Another solution that I can think of is to make a blank startup page C as the default page. In this C page, you can judge the user's role, and then jump to the corresponding page. But there will also be a redirection process. The experience is similar to the first method. Is there a better way? 

回答:

老张:

建议:在需要的时候才引导用户去登录注册。

citizen four:看标题回答:不能
祺爸💎:收购腾讯最优雅
csdoker:哈哈。。太真实了

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
没有找到哪里可以修改绑定公众号管理员?设置与开发,人员设置,修改功能在哪里?
公众号迁移,openid接口转换问题?
scroll-view横向滚动最后一个盒子的背景颜色为什么铺不满,麻烦大佬解惑一下?
获取用户基本信息(包括UnionID机制)
小程序直播创建直播返回空?
随便看看
微信公众号免300认证教程 4955
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 4073
小程序广告组件通过审核,但是小程序内没有显示广告? 4153
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8018
问题? 7254
如何快速搭建抽奖助手小程序(无需代码知识) 5038
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 5993
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5511
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5206
如何解决渲染层网络错误Failed to load media? 16561