diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
index 4301fbf2f0ed318fc1e730dbae34070b4ecbfbd6..46500510e8d25699a9928f5f0c9889121a17c336 100644
--- a/app/assets/javascripts/lib/utils/url_utility.js
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -287,9 +287,9 @@ export function visitUrl(url, external = false) {
     // See https://mathiasbynens.github.io/rel-noopener/
     const otherWindow = window.open();
     otherWindow.opener = null;
-    otherWindow.location = url;
+    otherWindow.location.assign(url);
   } else {
-    window.location.href = url;
+    window.location.assign(url);
   }
 }
 
diff --git a/spec/frontend/__helpers__/mock_window_location_helper.js b/spec/frontend/__helpers__/mock_window_location_helper.js
index de1e8c99b5468a0fbdbd3c71d54e9081104c21b0..48bc788afaa6ab00e4d0137b26a4af3483859edf 100644
--- a/spec/frontend/__helpers__/mock_window_location_helper.js
+++ b/spec/frontend/__helpers__/mock_window_location_helper.js
@@ -12,6 +12,7 @@ const useMockLocation = (fn) => {
 
   Object.defineProperty(window, 'location', {
     get: () => currentWindowLocation,
+    assign: jest.fn(),
   });
 
   beforeEach(() => {
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index 4bf3a779f00cd8459f5df5465cc22111e9ce3d12..f41fe140ba1f9dd94cfc6862bbb1311d5097e00c 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -406,7 +406,9 @@ describe('URL utility', () => {
 
       Object.defineProperty(window, 'location', {
         writable: true,
-        value: new URL(TEST_HOST),
+        value: {
+          assign: jest.fn(),
+        },
       });
     });
 
@@ -417,11 +419,15 @@ describe('URL utility', () => {
     it('navigates to a page', () => {
       urlUtils.visitUrl(mockUrl);
 
-      expect(window.location.href).toBe(mockUrl);
+      expect(window.location.assign).toHaveBeenCalledWith(mockUrl);
     });
 
     it('navigates to a new page', () => {
-      const otherWindow = {};
+      const otherWindow = {
+        location: {
+          assign: jest.fn(),
+        },
+      };
 
       Object.defineProperty(window, 'open', {
         writable: true,
@@ -431,7 +437,7 @@ describe('URL utility', () => {
       urlUtils.visitUrl(mockUrl, true);
 
       expect(otherWindow.opener).toBe(null);
-      expect(otherWindow.location).toBe(mockUrl);
+      expect(otherWindow.location.assign).toHaveBeenCalledWith(mockUrl);
     });
   });
 
diff --git a/spec/frontend/packages_and_registries/settings/project/settings/components/container_expiration_policy_form_spec.js b/spec/frontend/packages_and_registries/settings/project/settings/components/container_expiration_policy_form_spec.js
index a68087f7f57a823113eda35531102c4006520db3..e3feb99a9b52cdd9e9e4545aa8e3f21e171f1eed 100644
--- a/spec/frontend/packages_and_registries/settings/project/settings/components/container_expiration_policy_form_spec.js
+++ b/spec/frontend/packages_and_registries/settings/project/settings/components/container_expiration_policy_form_spec.js
@@ -286,8 +286,8 @@ describe('Container Expiration Policy Settings Form', () => {
 
         await submitForm();
 
-        expect(window.location.href.endsWith('settings-path?showSetupSuccessAlert=true')).toBe(
-          true,
+        expect(window.location.assign).toHaveBeenCalledWith(
+          'settings-path?showSetupSuccessAlert=true',
         );
       });