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

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

小程序怎么动态修改默认的启动页?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-