about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/mastodon/features/ui/components/media_modal.js20
1 files changed, 12 insertions, 8 deletions
diff --git a/app/javascript/mastodon/features/ui/components/media_modal.js b/app/javascript/mastodon/features/ui/components/media_modal.js
index c154da89a..6af0a101c 100644
--- a/app/javascript/mastodon/features/ui/components/media_modal.js
+++ b/app/javascript/mastodon/features/ui/components/media_modal.js
@@ -67,19 +67,23 @@ export default class MediaModal extends ImmutablePureComponent {
 
   componentDidMount () {
     window.addEventListener('keyup', this.handleKeyUp, false);
-    const history = this.context.router.history;
-    history.push(history.location.pathname, previewState);
-    this.unlistenHistory = history.listen(() => {
-      this.props.onClose();
-    });
+    if (this.context.router) {
+      const history = this.context.router.history;
+      history.push(history.location.pathname, previewState);
+      this.unlistenHistory = history.listen(() => {
+        this.props.onClose();
+      });
+    }
   }
 
   componentWillUnmount () {
     window.removeEventListener('keyup', this.handleKeyUp);
-    this.unlistenHistory();
+    if (this.context.router) {
+      this.unlistenHistory();
 
-    if (this.context.router.history.location.state === previewState) {
-      this.context.router.history.goBack();
+      if (this.context.router.history.location.state === previewState) {
+        this.context.router.history.goBack();
+      }
     }
   }