From 27bafabb647f0d7fb2ace29ce61e8d18f58c5fe0 Mon Sep 17 00:00:00 2001 From: Florin Date: Wed, 3 May 2023 23:14:04 -0700 Subject: [PATCH] Fix Back button going outside the app (#24835) --- app/javascript/mastodon/components/column_back_button.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/components/column_back_button.jsx b/app/javascript/mastodon/components/column_back_button.jsx index 12926bb25..653764778 100644 --- a/app/javascript/mastodon/components/column_back_button.jsx +++ b/app/javascript/mastodon/components/column_back_button.jsx @@ -21,7 +21,10 @@ export default class ColumnBackButton extends React.PureComponent { if (onClick) { onClick(); - } else if (window.history && window.history.state) { + } + // Check if there is a previous page in the app to go back to per https://stackoverflow.com/a/70532858/9703201 + // When upgrading to V6, check `location.key !== 'default'` instead per https://github.com/remix-run/history/blob/main/docs/api-reference.md#location + else if (router.location.key) { router.history.goBack(); } else { router.history.push('/');