Skip to content

Commit

Permalink
fix(router): 提前 router-change 事件到页面加载前
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Oct 19, 2022
1 parent 04b8dd4 commit edbcb87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/taro-router/src/router/mpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export async function createMultiRouter (

const pathName = config.pageName
const pageConfig = handler.pageConfig
eventCenter.trigger('__taroRouterChange', {
toLocation: {
path: pathName
}
})

let element
try {
element = await pageConfig.load?.()
Expand All @@ -54,12 +60,6 @@ export async function createMultiRouter (
if (!element) return
let enablePullDownRefresh = config?.window?.enablePullDownRefresh || false

eventCenter.trigger('__taroRouterChange', {
toLocation: {
path: pathName
}
})

if (pageConfig) {
setTitle(pageConfig.navigationBarTitleText ?? document.title)
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
Expand Down
12 changes: 6 additions & 6 deletions packages/taro-router/src/router/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export function createRouter (

const render: LocationListener = async ({ location, action }) => {
handler.pathname = decodeURI(location.pathname)
eventCenter.trigger('__taroRouterChange', {
toLocation: {
path: handler.pathname
}
})

let element, params
try {
const result = await router.resolve(handler.router.forcePath || handler.pathname)
Expand All @@ -70,12 +76,6 @@ export function createRouter (
const pageConfig = handler.pageConfig
let enablePullDownRefresh = config?.window?.enablePullDownRefresh || false

eventCenter.trigger('__taroRouterChange', {
toLocation: {
path: handler.pathname
}
})

if (pageConfig) {
document.title = pageConfig.navigationBarTitleText ?? document.title
setTitle(pageConfig.navigationBarTitleText ?? document.title)
Expand Down

0 comments on commit edbcb87

Please sign in to comment.