diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js
index 1f390e06406acd18f37f62cbdbbd98765c0472e5..80375f6156d0734e7db686d2397390b2d500a360 100644
--- a/app/assets/javascripts/diffs/store/actions.js
+++ b/app/assets/javascripts/diffs/store/actions.js
@@ -10,7 +10,12 @@ import axios from '~/lib/utils/axios_utils';
 
 import { HTTP_STATUS_NOT_FOUND, HTTP_STATUS_OK } from '~/lib/utils/http_status';
 import Poll from '~/lib/utils/poll';
-import { mergeUrlParams, getLocationHash, getParameterValues } from '~/lib/utils/url_utility';
+import {
+  mergeUrlParams,
+  getLocationHash,
+  getParameterValues,
+  removeParams,
+} from '~/lib/utils/url_utility';
 import notesEventHub from '~/notes/event_hub';
 import { generateTreeList } from '~/diffs/utils/tree_worker_utils';
 import { sortTree } from '~/ide/stores/utils';
@@ -394,7 +399,7 @@ export const fetchCoverageFiles = ({ commit, state }) => {
 export const setHighlightedRow = ({ commit }, { lineCode, event }) => {
   if (event && event.target.href) {
     event.preventDefault();
-    window.history.replaceState(null, undefined, event.target.href);
+    window.history.replaceState(null, undefined, removeParams(['pin'], event.target.href));
   }
   const fileHash = lineCode.split('_')[0];
   commit(types.SET_HIGHLIGHTED_ROW, lineCode);
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index a39f6705116f2483fab72f5daa0b345191a379dc..e480a5e480104ce2785c5f56b409c3a51c3ef356 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -702,6 +702,27 @@ describe('DiffsStoreActions', () => {
         { type: types.SET_CURRENT_DIFF_FILE, payload: 'ABC' },
       ]);
     });
+
+    it('should prevent default event', () => {
+      const preventDefault = jest.fn();
+      const target = { href: TEST_HOST };
+      const event = { target, preventDefault };
+      testAction(diffActions.setHighlightedRow, { lineCode: 'ABC_123', event }, {}, [
+        { type: types.SET_HIGHLIGHTED_ROW, payload: 'ABC_123' },
+        { type: types.SET_CURRENT_DIFF_FILE, payload: 'ABC' },
+      ]);
+      expect(preventDefault).toHaveBeenCalled();
+    });
+
+    it('should filter out pinned file param', () => {
+      const target = { href: `${TEST_HOST}/diffs?pin=foo#abc_11` };
+      const event = { target, preventDefault: jest.fn() };
+      testAction(diffActions.setHighlightedRow, { lineCode: 'ABC_123', event }, {}, [
+        { type: types.SET_HIGHLIGHTED_ROW, payload: 'ABC_123' },
+        { type: types.SET_CURRENT_DIFF_FILE, payload: 'ABC' },
+      ]);
+      expect(window.location.href).toBe(`${TEST_HOST}/diffs#abc_11`);
+    });
   });
 
   describe('assignDiscussionsToDiff', () => {