diff --git a/packages/taro-router/src/router/mpa.ts b/packages/taro-router/src/router/mpa.ts index 82810b23dcf8..aec2a3ee9877 100644 --- a/packages/taro-router/src/router/mpa.ts +++ b/packages/taro-router/src/router/mpa.ts @@ -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?.() @@ -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') { diff --git a/packages/taro-router/src/router/spa.ts b/packages/taro-router/src/router/spa.ts index 08a856608303..1c6ff4b76af7 100644 --- a/packages/taro-router/src/router/spa.ts +++ b/packages/taro-router/src/router/spa.ts @@ -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) @@ -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)