Skip to content

Commit

Permalink
fix(router-js): handle case when link is not of same host
Browse files Browse the repository at this point in the history
(cherry picked from commit 8cdda2e)
  • Loading branch information
NagariaHussain authored and mergify[bot] committed Oct 27, 2022
1 parent 1163e36 commit 1b70ec4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions frappe/public/js/frappe/router.js
Expand Up @@ -38,16 +38,17 @@ $("body").on("click", "a", function (e) {
return false;
};

const href = e.currentTarget.getAttribute("href");
const targetElement = e.currentTarget;
const href = targetElement.getAttribute("href");
const isOfSameHost = targetElement.hostname === window.location.hostname;

// click handled, but not by href
if (
e.currentTarget.getAttribute("onclick") || // has a handler
targetElement.getAttribute("onclick") || // has a handler
e.ctrlKey ||
e.metaKey || // open in a new tab
href === "#"
href === "#" // hash is home
) {
// hash is home
return;
}

Expand All @@ -57,20 +58,20 @@ $("body").on("click", "a", function (e) {

if (href && href.startsWith("#")) {
// target startswith "#", this is a v1 style route, so remake it.
return override(e.currentTarget.hash);
return override(targetElement.hash);
}

if (frappe.router.is_app_route(e.currentTarget.pathname)) {
if (isOfSameHost && frappe.router.is_app_route(targetElement.pathname)) {
// target has "/app, this is a v2 style route.

if (e.currentTarget.search) {
if (targetElement.search) {
frappe.route_options = {};
let params = new URLSearchParams(e.currentTarget.search);
let params = new URLSearchParams(targetElement.search);
for (const [key, value] of params) {
frappe.route_options[key] = value;
}
}
return override(e.currentTarget.pathname + e.currentTarget.hash);
return override(targetElement.pathname + targetElement.hash);
}
});

Expand Down

0 comments on commit 1b70ec4

Please sign in to comment.