taro icon indicating copy to clipboard operation
taro copied to clipboard

useRouter() 在京东小程序中返回null

Open Zahariel1942 opened this issue 1 year ago • 1 comments

相关平台

京东小程序

小程序基础库: 无 使用框架: React

复现步骤

export default function Page() {
  console.log(useRouter()); // null
  return <View>ProductDetail</View>;
}

期望结果

正常返回路由参数

实际结果

null

环境信息

👽 Taro v3.6.19


  Taro CLI 3.6.19 environment info:
    System:
      OS: macOS 14.2.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 18.17.1 - /usr/local/bin/node
      Yarn: 1.22.19 - /opt/homebrew/bin/yarn
      npm: 9.6.7 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.23 => 3.6.23
      @tarojs/components: 3.6.23 => 3.6.23
      @tarojs/helper: 3.6.23 => 3.6.23
      @tarojs/plugin-framework-react: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-alipay: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-h5: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-jd: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-qq: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-swan: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-tt: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-weapp: 3.6.23 => 3.6.23
      @tarojs/react: 3.6.23 => 3.6.23
      @tarojs/runtime: 3.6.23 => 3.6.23
      @tarojs/shared: 3.6.23 => 3.6.23
      @tarojs/taro: 3.6.23 => 3.6.23
      @tarojs/taro-loader: 3.6.23 => 3.6.23
      @tarojs/webpack5-runner: 3.6.23 => 3.6.23
      babel-preset-taro: 3.6.23 => 3.6.23
      eslint-config-taro: 3.6.23 => 3.6.23
      react: ^18.0.0 => 18.2.0
      taro-ui: ^3.2.2 => 3.3.0

Zahariel1942 avatar Feb 01 '24 06:02 Zahariel1942

useLoad()时或者延迟获取可稳定得到, 有时间差。

  useLoad((e) => {
    console.log('useLoad', e); // 有值
  });

Zahariel1942 avatar Feb 01 '24 06:02 Zahariel1942

使用京东小程序IDE(MacOS arm64 1.14.1)的模拟器遇到了相同的问题。在真机上没问题。

原因是模拟器在打开新页面时会调用一次 onHide,onHide 会清空 Current.router = null

已经同步给他们IDE的开发同学,反馈说下个版本修复。

1oo1 avatar Mar 01 '24 07:03 1oo1