Skip to content

Commit

Permalink
fix(router): 补齐 app 启动所需参数
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 23, 2022
1 parent 790c3ab commit 223ccc1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 9 additions & 6 deletions packages/taro-router/src/router/mpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export async function createMultiRouter (
) {
RouterConfig.config = config
const handler = new MultiPageHandler(config)
const launchParam = {
// 其他参数, 需要再抹平
query: handler.getQuery()
const launchParam: Taro.getLaunchOptionsSync.LaunchOptions = {
path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
query: handler.getQuery(),
scene: 0,
shareTicket: '',
referrerInfo: {}
}
app.onLaunch?.(launchParam)
app.onLaunch?.(launchParam as Record<string, any>)
app.onError && window.addEventListener('error', e => app.onError?.(e.message))

const pathName = config.pageName
Expand Down Expand Up @@ -68,11 +71,11 @@ export async function createMultiRouter (
delete loadConfig['load']
const page = createPageConfig(
enablePullDownRefresh ? hooks.call('createPullDownComponent', el, location.pathname, framework, config.PullDownRefresh) : el,
pathName + stringify(launchParam),
pathName + stringify(launchParam as Record<string, any>),
{},
loadConfig
)
handler.load(page, pageConfig)

app.onShow?.(launchParam)
app.onShow?.(launchParam as Record<string, any>)
}
12 changes: 7 additions & 5 deletions packages/taro-router/src/router/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export function createRouter (
}
})
const router = new UniversalRouter(routes, { baseUrl: basename || '' })
const launchParam = {
// 其他参数, 需要再抹平
const launchParam: Taro.getLaunchOptionsSync.LaunchOptions = {
path: handler.homePage,
query: handler.getQuery(stacks.length)
query: handler.getQuery(stacks.length),
scene: 0,
shareTicket: '',
referrerInfo: {}
}
app.onLaunch?.(launchParam)
app.onLaunch?.(launchParam as Record<string, any>)
app.onError && window.addEventListener('error', e => app.onError?.(e.message))

const render: LocationListener = async ({ location, action }) => {
Expand Down Expand Up @@ -141,7 +143,7 @@ export function createRouter (

render({ location: history.location, action: LocationAction.Push })

app.onShow?.(launchParam)
app.onShow?.(launchParam as Record<string, any>)

return history.listen(render)
}

0 comments on commit 223ccc1

Please sign in to comment.