修复讲解列表返回导览首页
This commit is contained in:
@@ -79,6 +79,7 @@ type ExplainListHistoryState = {
|
||||
}
|
||||
|
||||
let explainListHistoryPushed = false
|
||||
let isConsumingExplainListHistory = false
|
||||
let isReturningToGuideHome = false
|
||||
|
||||
type PageStackEntry = {
|
||||
@@ -96,6 +97,14 @@ const guideHomeUrl = () => (
|
||||
shouldUseHostNavigation.value ? guideTopTabUrl('guide') : GUIDE_HOME_URL
|
||||
)
|
||||
|
||||
const isExplainListHistoryState = (state: unknown): state is ExplainListHistoryState => (
|
||||
Boolean(
|
||||
state
|
||||
&& typeof state === 'object'
|
||||
&& (state as ExplainListHistoryState).museumGuidePage === 'explain-list'
|
||||
)
|
||||
)
|
||||
|
||||
const showGuideHomeReturnError = () => {
|
||||
isReturningToGuideHome = false
|
||||
uni.showToast({
|
||||
@@ -111,8 +120,22 @@ const reLaunchGuideHome = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const consumeExplainListHistory = () => {
|
||||
if (
|
||||
typeof window === 'undefined'
|
||||
|| !explainListHistoryPushed
|
||||
|| !isExplainListHistoryState(window.history.state)
|
||||
) return false
|
||||
|
||||
// 根栈压入了同 URL 标记,先消费它,避免回首页后再次回流到讲解列表。
|
||||
isConsumingExplainListHistory = true
|
||||
window.history.back()
|
||||
return true
|
||||
}
|
||||
|
||||
const returnToGuideHome = () => {
|
||||
if (isReturningToGuideHome) return
|
||||
if (isReturningToGuideHome || isConsumingExplainListHistory) return
|
||||
if (consumeExplainListHistory()) return
|
||||
|
||||
isReturningToGuideHome = true
|
||||
const pages = getPageStack()
|
||||
@@ -138,14 +161,6 @@ const returnToGuideHome = () => {
|
||||
reLaunchGuideHome()
|
||||
}
|
||||
|
||||
const isExplainListHistoryState = (state: unknown): state is ExplainListHistoryState => (
|
||||
Boolean(
|
||||
state
|
||||
&& typeof state === 'object'
|
||||
&& (state as ExplainListHistoryState).museumGuidePage === 'explain-list'
|
||||
)
|
||||
)
|
||||
|
||||
const pushExplainListHistory = () => {
|
||||
if (typeof window === 'undefined' || getPageStack().length > 1) return
|
||||
if (explainListHistoryPushed) return
|
||||
@@ -168,10 +183,12 @@ const handleExplainListHistoryPopState = (event: PopStateEvent) => {
|
||||
|
||||
if (isExplainListHistoryState(event.state)) {
|
||||
explainListHistoryPushed = true
|
||||
isConsumingExplainListHistory = false
|
||||
return
|
||||
}
|
||||
|
||||
explainListHistoryPushed = false
|
||||
isConsumingExplainListHistory = false
|
||||
returnToGuideHome()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user