Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5配置了customRoutes,二级页调用switchTab返回tab页白屏 #6878

Closed
justrustc opened this issue Jul 2, 2020 · 1 comment · Fixed by #7344
Closed

H5配置了customRoutes,二级页调用switchTab返回tab页白屏 #6878

justrustc opened this issue Jul 2, 2020 · 1 comment · Fixed by #7344
Assignees
Labels
A-api Area - H5 API 相关 A-router Area - H5 路由相关 T-h5 Target - 编译到 H5 V-2 Version - 2.x

Comments

@justrustc
Copy link

justrustc commented Jul 2, 2020

相关平台

H5

复现仓库

https://github.com/yulrosy/taro-issue.git
浏览器版本: Chrome 83
使用框架: React

复现步骤

  1. yarn dev:h5
  2. 进入二级页面
  3. 返回tab页

期望结果

tab页正常显示

实际结果

tab页空白

环境信息

  Taro CLI 2.2.9 environment info:
    System:
      OS: macOS 10.15.4
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.16.2 - /var/folders/fs/4t8db8ns0_5g18dbtgs9h2fc0000gn/T/yarn--1593659530960-0.5098437793808264/node
      Yarn: 1.22.4 - /var/folders/fs/4t8db8ns0_5g18dbtgs9h2fc0000gn/T/yarn--1593659530960-0.5098437793808264/yarn
      npm: 6.14.4 - ~/.nvs/default/bin/npm
    npmPackages:
      @tarojs/cli: 2.2.9 => 2.2.9 
      @tarojs/components: 2.2.9 => 2.2.9 
      @tarojs/mini-runner: 2.2.9 => 2.2.9 
      @tarojs/plugin-sass: 2.2.9 => 2.2.9 
      @tarojs/plugin-terser: ^2.2.9 => 2.2.9 
      @tarojs/router: 2.2.9 => 2.2.9 
      @tarojs/taro: 2.2.9 => 2.2.9 
      @tarojs/taro-h5: 2.2.9 => 2.2.9 
      @tarojs/taro-weapp: 2.2.9 => 2.2.9 
      @tarojs/webpack-runner: 2.2.9 => 2.2.9 
      nerv-devtools: ^1.5.7 => 1.5.7 
      nervjs: ^1.5.7 => 1.5.7 
@konghuawei
Copy link

我也遇到这种情况,解决方案【暂时】:

/**
 * // NOTE 后端返回的 url 可能是网页链接,需要在 webview 中打开
 * 也可能是小程序自身的链接,只能用 navigate/redirect 之类的打开
 * 就需要有个地方统一判断处理
 */
export default function jump(options) {
  const { url, title = '', payload = {}, method = 'navigateTo' } = options

  if (/^https?:\/\//.test(url)) {
    Taro[method]({
      url: urlStringify(PAGE_WEBVIEW, { url, title })
    })
  } else if (/^\/pages\//.test(url)) {
    // TODO H5 不支持 switchTab,暂时 hack 下
    if (process.env.TARO_ENV === 'h5' && method === 'switchTab') {
      Taro.navigateBack({ delta: Taro.getCurrentPages().length - 1 })
      setTimeout(() => { Taro.redirectTo({ url }) }, 100)
      return
    }

    Taro[method]({
      url: urlStringify(url, payload)
    })
  }
}

在二级页面调用就行了

import jump from '../../../utils/jump'

jump({ url: item.url, method: 'switchTab' })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-api Area - H5 API 相关 A-router Area - H5 路由相关 T-h5 Target - 编译到 H5 V-2 Version - 2.x
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants