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

fix: revert path decoding in interfaces/redirectTo #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ambar
Copy link

@ambar ambar commented Dec 2, 2020

  • 测试:babel-cli 应该加到 dev deps 不然测试无法运行、修复了三处测试运行中的错误
  • 修复:6c6d2f6 中错误将 path decode 了,这会导致参数丢失,撤销它的改动,并补充测试

问题

当前 cml.navigateTo API 会丢失参数,而使用 navigator 组件不会。

通常我们使用 webview 的时候会有自定义参数需要透传,像这样:

<navigator url="/pages/webview?url={{encodedUrl}}" /> 

<script>
Page({
  data: {
    encodedUrl: encodeURIComponent('https://www.example.com/?foo=1&bar=2'),
  }
})
<script>

同时也可能会在需要回调中使用调用基础 API,像这样:

// 正常
const url = 'https://www.example.com/?foo=1&bar=2'
wx.navigateTo({url: `/webview?url=${encodeURIComponent(url)}`})

但如果在使用 cml 中则会丢失参数,因为它进行了一次多余的 decode:

const url = 'https://www.example.com/?foo=1&bar=2'
// 期望正常,但丢失了参数!
cml.navigateTo({path: `/webview?url=${encodeURIComponent(url)}`})
// 期望正常,但也丢失了参数!
cml.navigateTo({path: `/webview`, query: {url}})

框架问题非基础 API 问题

didi/chameleon#387 中反映的问题是框架的,不是基础 API,经测试:

要解决它可以考虑在 cml 框架中解决,自动 decode 再注入参数(判断有必要的平台)。

额外想法

  • 可以考虑把 mocha/chai 替换成 jest —— mocha 的测试没有隔离(每个文件会互相污染,特别是的全局环境变量),而 chai 的 API 又太繁琐不好用
  • navigateTo({url}) 应该支持?习惯上 wx/swan 中是这样使用的,但 cml 中直接没有处理,直接丢弃了 —— 不然在使用一个 url 已经带参数的情况还可能需要想把它转换 path/query 格式

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

Successfully merging this pull request may close these issues.

1 participant