@@ -54,6 +54,12 @@ export function MobileBottomTab() {
5454 const pathname = usePathname ( ) ;
5555 const { theme, toggleTheme } = useTheme ( ) ;
5656
57+ // Track previous pathname for back navigation
58+ const prevPathname = useRef < string | null > ( null ) ;
59+ useEffect ( ( ) => {
60+ return ( ) => { prevPathname . current = pathname ; } ;
61+ } , [ pathname ] ) ;
62+
5763 // --- Scroll hide logic ---
5864 const enableHideByScroll = useMemo ( ( ) => {
5965 return hideOnRoutes . some ( ( m ) => matchRoute ( pathname , m ) ) ;
@@ -209,9 +215,17 @@ export function MobileBottomTab() {
209215 navigateTo ( tabs [ clampedIndex ] . href ) ;
210216 }
211217 } else if ( touchedTabIndex . current !== null ) {
212- // Tap on a tab — navigate (even if same tab, pathname might differ)
213218 const i = touchedTabIndex . current ;
214- if ( tabs [ i ] . href !== pathname ) {
219+ const isPostPage = pathname . startsWith ( "/post" ) ;
220+
221+ if ( isPostPage && tabs [ i ] . href === "/" ) {
222+ // On post page, Undo2 button: go back if previous page was internal, else home
223+ if ( prevPathname . current && ! prevPathname . current . startsWith ( "/post" ) ) {
224+ document . dispatchEvent ( new Event ( "transition-back" ) ) ;
225+ } else {
226+ navigateTo ( "/" ) ;
227+ }
228+ } else if ( tabs [ i ] . href !== pathname ) {
215229 navigateTo ( tabs [ i ] . href ) ;
216230 }
217231 }
0 commit comments