Skip to content

Commit

Permalink
fix(getCurrentPageQuery): 对值执行 decodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Aug 28, 2020
1 parent 69fcf00 commit c46cacd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/mp/getCurrentPageQuery.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { ensureInMiniProgram } from './ensureInMiniProgram'
import { mapValues } from '../utils'

/**
* 获取当前页面的查询参数。
* 获取当前页面的查询参数,已经对每个值执行了 decodeURIComponent
*
* @returns 返回当前页面的查询参数
*/
export function getCurrentPageQuery<T extends Record<string, string>>(): T {
export function getCurrentPageQuery<
T extends Record<string, string | undefined>
>(): T {
return ensureInMiniProgram(() => {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const query = currentPage.options || {}
const query = mapValues(
currentPage.options || {},
value => value && decodeURIComponent(value),
)
return (query as any) as T
})
}

0 comments on commit c46cacd

Please sign in to comment.