Skip to content

Commit

Permalink
fix(router-js): handle case when link is not of same host (backport #…
Browse files Browse the repository at this point in the history
…18590) (#18600)

* fix(router-js): handle case when link is not of same host

(cherry picked from commit 8cdda2e)

# Conflicts:
#	frappe/public/js/frappe/router.js

* fix(formatting): use snake case for variable names

(cherry picked from commit ccbd6ff)

# Conflicts:
#	frappe/public/js/frappe/router.js

* chore: resolved conflicts

Co-authored-by: Hussain Nagaria <hussainbhaitech@gmail.com>
Co-authored-by: Shariq Ansari <30859809+shariquerik@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 28, 2022
1 parent 0493ccd commit 55e96a5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions frappe/public/js/frappe/router.js
Expand Up @@ -38,12 +38,17 @@ $('body').on('click', 'a', function(e) {
return false;
};

const href = e.currentTarget.getAttribute('href');
const target_element = e.currentTarget;
const href = target_element.getAttribute("href");
const is_on_same_host = target_element.hostname === window.location.hostname;

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

Expand All @@ -53,12 +58,12 @@ $('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(target_element.hash);
}

if (frappe.router.is_app_route(e.currentTarget.pathname)) {
if (is_on_same_host && frappe.router.is_app_route(target_element.pathname)) {
// target has "/app, this is a v2 style route.
return override(e.currentTarget.pathname + e.currentTarget.hash);
return override(target_element.pathname + target_element.hash);
}

});
Expand Down

0 comments on commit 55e96a5

Please sign in to comment.