Skip to content

Commit

Permalink
feat(router): reLaunch 移除冗余页面节点 fix #9724
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Dec 15, 2021
1 parent d95a28b commit aa8d547
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/taro-router/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function processNavigateUrl (option: Option) {
return pathPieces
}

async function navigate (option: Option | NavigateBackOption, method: 'navigateTo' | 'navigateBack' | 'redirectTo' | 'reLaunch') {
async function navigate (option: Option | NavigateBackOption, method: 'navigateTo' | 'navigateBack' | 'switchTab' | 'redirectTo' | 'reLaunch') {
return new Promise<TaroGeneral.CallbackResult>((resolve, reject) => {
const { success, complete, fail } = option
const unListen = history.listen(() => {
Expand All @@ -67,7 +67,10 @@ async function navigate (option: Option | NavigateBackOption, method: 'navigateT
const state = { timestamp: Date.now() }
if (method === 'navigateTo') {
history.push(pathPieces, state)
} else if (method === 'redirectTo') {
} else if (method === 'redirectTo' || method === 'switchTab') {
history.replace(pathPieces, state)
} else if (method === 'reLaunch') {
stacks.delta = stacks.length
history.replace(pathPieces, state)
} else if (method === 'reLaunch') {
stacks.delta = stacks.length
Expand All @@ -90,7 +93,7 @@ export function navigateTo (option: Taro.navigateTo.Option): ReturnType<typeof T
return navigate(option, 'navigateTo')
}

export function redirectTo (option: Taro.redirectTo.Option): ReturnType<typeof Taro.reLaunch> {
export function redirectTo (option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo> {
return navigate(option, 'redirectTo')
}

Expand All @@ -102,7 +105,7 @@ export function navigateBack (options: Taro.navigateBack.Option = { delta: 1 }):
}

export function switchTab (option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab> {
return redirectTo(option)
return navigate(option, 'switchTab')
}

export function reLaunch (option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch> {
Expand Down

0 comments on commit aa8d547

Please sign in to comment.