fix: go to previous page after current page delete - #13156
Conversation
After deleting the current page or focused block, restore the previous history entry instead of sending the user home. Fall back to replacing the current entry with home only when there is no previous entry. Skip this on mobile so the native stack is not double-popped. Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new route-handler tests mutate js/window.history directly, which is commonly non-writable and can make the test suite fail or become flaky.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the delete-page navigation behavior so that when the currently viewed page or focused block is deleted/recycled, Logseq returns to the previous route (via history back) rather than redirecting to home, with a fallback that replaces the current entry with home when no prior history exists; non-current deletions do not affect navigation, and mobile avoids double-pop behavior.
Changes:
- Add
route-handler/redirect-to-previous!with a no-history fallback to:homeusing:push false. - Update outliner pipeline delete/recycle hook handling to use
redirect-to-previous!on desktop for current-route removals (skip on mobile; skip recycle during:initial-pages?). - Add targeted tests for pipeline navigation decisions and the route-handler history-back vs home fallback behavior.
File summaries
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Description
Fixes db-test#1135.
After deleting the page (or focused block) you are viewing, Logseq now returns to the previously visited page/block in history instead of sending you home.
Deleting a page that is not the current route does not change navigation.
Behavior
history.back()to the previous page/block.history.back; the pipeline does not also go back (avoids a double pop after Fix UI #1135: redirect to previous page instead of home on page delete #13153).Tests
frontend.modules.outliner.pipeline-testcovers current vs non-current recycle/hard-delete, focused-block delete, mobile skip, and graph-load (:initial-pages?).frontend.handler.route-testcovers history-back vs home fallback.Notes
#13153 already replaced the hardcoded home redirect with
history.back. This follow-up unifies that path, adds the empty-history fallback, stops mobile double-back on recycle, and adds tests. It does not change #1137 or #1139.