-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(getCurrentPageQuery): 对值执行 decodeURIComponent
- Loading branch information
Showing
1 changed file
with
9 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |