Skip to content

Commit cff064c

Browse files
authored
fix: prevent link to be followed before testing the header (#1361)
* fix: prevent link to be followed before testing the header * refactor: prettify
1 parent 29fcd08 commit cff064c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ var setupSearchButtons = () => {
288288
* @param {event} event the event that trigger the check
289289
*/
290290
function checkPageExistsAndRedirect(event) {
291+
// ensure we don't follow the initial link
292+
event.preventDefault();
293+
291294
const currentFilePath = `${DOCUMENTATION_OPTIONS.pagename}.html`;
292295
const tryUrl = event.currentTarget.getAttribute("href");
293296
let otherDocsHomepage = tryUrl.replace(currentFilePath, "");
@@ -299,10 +302,6 @@ function checkPageExistsAndRedirect(event) {
299302
.catch((error) => {
300303
location.href = otherDocsHomepage;
301304
});
302-
303-
// ↓ this prevents the browser from following the href of the clicked node
304-
// ↓ (which is fine because this function takes care of redirecting)
305-
event.preventDefault();
306305
}
307306

308307
/**

0 commit comments

Comments
 (0)