Skip to content

Commit

Permalink
fix: 优化路由接口以及修复onResize回调参数缺失的字段
Browse files Browse the repository at this point in the history
  • Loading branch information
guoenxuan committed Dec 25, 2023
1 parent 5625764 commit 4f41c13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 11 additions & 0 deletions packages/taro-router/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ async function navigate (option: Option | NavigateBackOption, method: MethodName
if ('url' in option) {
const pathPieces = processNavigateUrl(option)
const state = { timestamp: Date.now() }
if (pathPieces.pathname) {
const originPath = routesAlias.getOrigin(pathPieces.pathname)
const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath
if (!RouterConfig.pages.includes(pagePath)) {
const res = { errMsg: `${method}:fail page ${pagePath} is not found` }
fail?.(res)
complete?.(res)
reject(res)
return
}
}
if (method === 'navigateTo') {
history.push(pathPieces, state)
} else if (method === 'redirectTo' || method === 'switchTab') {
Expand Down
18 changes: 12 additions & 6 deletions packages/taro-router/src/events/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ export function bindPageResize (page: PageInstance) {
pageResizeFn && window.removeEventListener('resize', pageResizeFn)

pageResizeFn = function () {
page.onResize && page.onResize({
size: {
windowHeight: window.innerHeight,
windowWidth: window.innerWidth
}
})
if (page.onResize) {
const mediaQuery = window.matchMedia('(orientation: portrait)')
page.onResize({
deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
size: {
windowHeight: window.innerHeight,
windowWidth: window.innerWidth,
screenHeight: window.screen.height,
screenWidth: window.screen.width,
}
})
}
}

window.addEventListener('resize', pageResizeFn, false)
Expand Down

0 comments on commit 4f41c13

Please sign in to comment.