Skip to content

Commit

Permalink
fix(runtime): 调整路由参数逻辑, fix #11713
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed May 20, 2022
1 parent 226d44a commit 49660b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/taro-runtime/src/current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppInstance, PageInstance } from './dsl/instance'
export interface Router {
params: Record<string, unknown>,
path: string,
$taroPath: string,
onReady: string,
onHide: string,
onShow: string
Expand Down
14 changes: 7 additions & 7 deletions packages/taro-runtime/src/dsl/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco
Current.router = {
params: page.$taroParams!,
path: addLeadingSlash(router),
$taroPath: page.$taroPath,
onReady: getOnReadyEventKey(id),
onShow: getOnShowEventKey(id),
onHide: getOnHideEventKey(id)
Expand All @@ -111,24 +112,23 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco
let loadResolver: (...args: unknown[]) => void
let hasLoaded: Promise<void>
const config: PageInstance = {
[ONLOAD] (this: MpInstance, options: Record<string, unknown> = {}, cb?: Func) {
[ONLOAD] (this: MpInstance, options: Readonly<Record<string, unknown>> = {}, cb?: Func) {
hasLoaded = new Promise(resolve => { loadResolver = resolve })

perf.start(PAGE_INIT)

Current.page = this as any
this.config = pageConfig || {}
options.$taroTimestamp = Date.now()

// this.$taroPath 是页面唯一标识,不可变,因此页面参数 options 也不可变
this.$taroPath = getPath(id, options)
const $taroPath = this.$taroPath
// this.$taroPath 是页面唯一标识
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() })
const $taroPath = this.$taroPath = getPath(id, uniqueOptions)
if (process.env.TARO_ENV === 'h5') {
config.path = this.$taroPath
config.path = $taroPath
}
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
if (this.$taroParams == null) {
this.$taroParams = Object.assign({}, options)
this.$taroParams = uniqueOptions
}

setCurrentRouter(this)
Expand Down
10 changes: 1 addition & 9 deletions packages/taro-runtime/src/next-tick.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { Current } from './current'
import { getPath } from './dsl/common'
import { TaroRootElement } from './dom/root'
import { document } from './bom/document'

import type { Func } from './interface'

function removeLeadingSlash (path?: string) {
if (path == null) {
return ''
}
return path.charAt(0) === '/' ? path.slice(1) : path
}

export const nextTick = (cb: Func, ctx?: Record<string, any>) => {
const router = Current.router
const timerFunc = () => {
Expand All @@ -22,7 +14,7 @@ export const nextTick = (cb: Func, ctx?: Record<string, any>) => {

if (router !== null) {
let pageElement: TaroRootElement | null = null
const path = getPath(removeLeadingSlash(router.path), router.params)
const path = router.$taroPath
pageElement = document.getElementById<TaroRootElement>(path)
if (pageElement?.pendingUpdate) {
if (process.env.TARO_ENV === 'h5') {
Expand Down

0 comments on commit 49660b7

Please sign in to comment.