onLaunch 调用 wx.redirectTo 没有效果
发布于 5 年前 作者 duxiulan 20276 次浏览 来自 问答

我想实现一个登录流程,

就是在 App 的 onLaunch 的时候,判断是否存在 token,如果没有,跳转到登录页面,但是页面不会跳转。

App({
  onLaunch: function(options) {
    let token = wx.getStorageSync('token');
    if (!token) {
      wx.redirectTo({
        url: '/pages/login/login',
        success: (res) => {
          console.log(res) // success {errMsg: "redirectTo:ok"}
        },
        fail: (err) => {
          console.log(err)
        }
      })
    }
  }
});

success 回调会被调用,但是页面没有跳转

2 回复

试试wx.reLaunch()

这个注册程序的时候还有说明的,页面还没有生产的

回到顶部