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

[Taro3 alpha7] useRouter 在小程序隐藏再次显示后, params 丢失. #5707

Closed
cncolder opened this issue Mar 15, 2020 · 5 comments
Closed
Assignees

Comments

@cncolder
Copy link
Contributor

cncolder commented Mar 15, 2020

问题描述

复现步骤

  1. 微信开发者工具中指定编译模式 { "query": "id=123" }
  2. 页面使用 useRouter hook.
  3. 使用 chooseImage 或 openSettings 等 API 触发 app.onDidHide
  4. 返回触发 app.onDidShow
  5. params 丢失.
import React from 'react'
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'

export default () => {
	const router = Taro.useRouter()

	return <View onClick={() => Taro.chooseImage()}>{JSON.stringify(router.params)}</View>
}

期望行为

报错信息

系统信息

taro 3.0.0.alpha.7

补充信息

临时解决方案

export function useMemoRouter() {
    const router = useRouter()

    // BUGFIX: Taro 3.0.0-alpha.7 在打开相册等操作后, router params 丢失, 为防止这种情况发生, memo 该值.
    return useMemo(() => router, [])
}

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

@taro-bot
Copy link

taro-bot bot commented Mar 15, 2020

CC @Chen-jj

@taro-bot
Copy link

taro-bot bot commented Mar 15, 2020

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@yuche yuche assigned yuche and unassigned Chen-jj Mar 16, 2020
@yuche
Copy link
Contributor

yuche commented Mar 16, 2020

使用了补充信息的解决方案的注释我没看懂,按理来说用了 useMemo 就应该不会再改变了,应该能解决这个问题才是。

@cncolder
Copy link
Contributor Author

@yuche 补充信息里的注释是我写在真实项目里, 直接复制过来的.

我要表达的意思是一个页面的路由参数是不可能发生动态改变的, 而现在 alpha7 的表现是在页面隐藏再重新显示时却发生了变化, 这是我不希望看到的, 所以我写了这个自定义 hook 来防止这种变化.

@yuche
Copy link
Contributor

yuche commented Mar 16, 2020

@yuche 补充信息里的注释是我写在真实项目里, 直接复制过来的.

我要表达的意思是一个页面的路由参数是不可能发生动态改变的, 而现在 alpha7 的表现是在页面隐藏再重新显示时却发生了变化, 这是我不希望看到的, 所以我写了这个自定义 hook 来防止这种变化.

我的理解是用一个 useMemo 包住确实能解决 issue 描述的问题且(暂时)没有副作用,如果要修复这个问题,Taro 本身也会这样改。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants