Skip to content

fix: prevent BackButton from navigating outside the app#1196

Closed
zp6 wants to merge 1 commit into
entrius:testfrom
zp6:fix/back-button-navigation
Closed

fix: prevent BackButton from navigating outside the app#1196
zp6 wants to merge 1 commit into
entrius:testfrom
zp6:fix/back-button-navigation

Conversation

@zp6
Copy link
Copy Markdown

@zp6 zp6 commented May 15, 2026

Fixes #1162

The shared BackButton used on every detail page now checks document.referrer to determine whether the previous history entry belongs to this app. When the referrer is missing or points to a different origin (fresh tab, shared link, bookmark), the button falls back to the configured in-app route instead of calling
avigate(-1) which would leave the app.

Changes:

  • Added isInAppNavigation() helper that checks document.referrer origin against window.location.origin`n- BackButton now only steps through browser history when the previous entry is verifiably an in-app page
  • Falls back to state.backTo or the o prop when the referrer is empty/external

Testing:

  • Open a detail page from a fresh tab or shared link ? Back button navigates to the parent list page
  • Navigate within the app to a detail page ? Back button correctly goes to the previous in-app page
  • Verified no regression in normal in-app navigation flows

Fixes entrius#1162

The shared BackButton used on every detail page now checks document.referrer
to determine whether the previous history entry belongs to this app. When the
referrer is missing or points to a different origin (fresh tab, shared link,
bookmark), the button falls back to the configured in-app route instead of
calling navigate(-1) which would leave the app.

This mirrors the fix already applied to the 404 page's own back button and
extends it to every detail page that uses the shared BackButton component.
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 15, 2026
@anderdc
Copy link
Copy Markdown
Collaborator

anderdc commented May 15, 2026

Duplicate of #1160 which is better scoped/implemented. Closing.

@anderdc anderdc closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared "Back" button on detail pages can navigate outside the app when the page was opened from a fresh tab or shared link

2 participants