fix: back button returns to parent agent instead of homepage
When viewing a child agent (an agent with parentAgentId set), the back button now navigates to the parent agent screen instead of always going to the homepage. Added handleBack callback in AgentScreenContent that checks for parentAgentId and routes accordingly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
3f0a08ad50
commit
7d233777db
@@ -153,6 +153,26 @@ function AgentScreenContent({ serverId, agentId, onBack }: AgentScreenContentPro
|
||||
resolvedAgentId ? state.sessions[serverId]?.agents?.get(resolvedAgentId) : undefined
|
||||
);
|
||||
|
||||
// Get parent agent ID for back navigation
|
||||
const parentAgentId = agent?.parentAgentId;
|
||||
|
||||
// Navigate to parent agent if this is a child, otherwise go to homepage
|
||||
const handleBack = useCallback(() => {
|
||||
if (parentAgentId) {
|
||||
// Child agent: navigate back to parent
|
||||
router.push({
|
||||
pathname: "/agent/[serverId]/[agentId]",
|
||||
params: {
|
||||
serverId: serverId,
|
||||
agentId: parentAgentId,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Root agent: navigate to homepage
|
||||
onBack();
|
||||
}
|
||||
}, [parentAgentId, router, serverId, onBack]);
|
||||
|
||||
// Select the agents Map directly - this is a stable reference that only changes when agents are added/removed
|
||||
const allAgents = useSessionStore((state) => state.sessions[serverId]?.agents);
|
||||
|
||||
@@ -507,7 +527,7 @@ function AgentScreenContent({ serverId, agentId, onBack }: AgentScreenContentPro
|
||||
{/* Header */}
|
||||
<BackHeader
|
||||
title={agent.title || "Agent"}
|
||||
onBack={onBack}
|
||||
onBack={handleBack}
|
||||
rightContent={
|
||||
<View ref={menuButtonRef} collapsable={false}>
|
||||
<Pressable onPress={handleOpenMenu} style={styles.menuButton}>
|
||||
|
||||
@@ -697,13 +697,14 @@ interface ToolCallSheetData {
|
||||
4. ❌ Pressed back button (arrow icon in header) - navigated to **homepage** instead of parent agent screen
|
||||
**Root cause**: The `handleNavigateToChildAgent` in `[agentId].tsx` uses `router.push()` which adds to history, but the back button handler (`handleBack` at line ~202) uses `router.canGoBack() ? router.back() : router.push("/")` - this is working correctly for browser history. The issue is that when navigating from Sub-Agents menu, it closes the menu first and the navigation happens. The browser history should be: homepage → parent → child. But the navigation log shows `from: agent, to: home` suggesting the back action went directly to homepage. This may be due to router history being reset when the menu modal closes or a race condition.
|
||||
|
||||
- [ ] **Fix**: Ensure back button returns to parent agent when navigating from sub-agent menu.
|
||||
- [x] **Fix**: Ensure back button returns to parent agent when navigating from sub-agent menu.
|
||||
|
||||
- Investigate why router history shows `from: agent, to: home` instead of `from: child, to: parent`
|
||||
- The navigation from parent to child via Sub-Agents menu should properly add to browser history
|
||||
- Check if menu dismissal or modal closing is affecting router state
|
||||
- Test with `router.replace()` vs `router.push()` in `handleNavigateToChildAgent`
|
||||
- Ensure expo-router preserves navigation stack when navigating between agent screens
|
||||
- **Done (2025-12-22 13:55)**: Fixed back navigation for child agents. The issue was that `BackHeader` always used the `onBack` prop which called `handleBackToHome` (always navigates to homepage). Added `handleBack` callback in `AgentScreenContent` that checks if the agent has a `parentAgentId` - if so, navigates to the parent agent screen; otherwise falls back to homepage navigation. Typecheck passes.
|
||||
|
||||
- [ ] **Test**: Re-verify back button after fix.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user