diff --git a/frontend/src/metabase/hoc/ModalRoute.jsx b/frontend/src/metabase/hoc/ModalRoute.jsx
index 80bb8650b37bb1c498ff6e70fdaeefdf7545f20d..011458654a2e1aa4cdbc08ba78a8b335420b5611 100644
--- a/frontend/src/metabase/hoc/ModalRoute.jsx
+++ b/frontend/src/metabase/hoc/ModalRoute.jsx
@@ -5,6 +5,15 @@ import { push } from "react-router-redux";
 import { connect } from "react-redux";
 import Modal from "metabase/components/Modal";
 
+export const getParentPath = (route, location) => {
+  const fullPathSegments = location.pathname.split("/");
+  const routeSegments = route.path.split("/");
+
+  fullPathSegments.splice(-routeSegments.length);
+
+  return fullPathSegments.join("/");
+};
+
 const ModalWithRoute = (ComposedModal, modalProps = {}) =>
   connect(
     null,
@@ -15,14 +24,10 @@ const ModalWithRoute = (ComposedModal, modalProps = {}) =>
         ComposedModal.name}]`;
 
       onClose = () => {
-        const {
-          location: { pathname },
-        } = this.props;
-        const urlWithoutLastSegment = pathname.substring(
-          0,
-          pathname.lastIndexOf("/"),
-        );
-        this.props.onChangeLocation(urlWithoutLastSegment);
+        const { location, route } = this.props;
+
+        const parentPath = getParentPath(route, location);
+        this.props.onChangeLocation(parentPath);
       };
 
       render() {