fix: Pass URL hash separately
This commit is contained in:
parent
b9d4974360
commit
895dab8535
1 changed files with 20 additions and 15 deletions
|
|
@ -31,20 +31,21 @@ window.addEventListener("popstate", (e) => {
|
|||
return false;
|
||||
});
|
||||
|
||||
// routing v2, capture all clicks so that the target is managed with push-state
|
||||
// Capture all clicks so that the target is managed with push-state
|
||||
$("body").on("click", "a", function (e) {
|
||||
let override = (route) => {
|
||||
const target_element = e.currentTarget;
|
||||
const href = target_element.getAttribute("href");
|
||||
const is_on_same_host = target_element.hostname === window.location.hostname;
|
||||
|
||||
const override = (route) => {
|
||||
e.preventDefault();
|
||||
frappe.set_route(route);
|
||||
return false;
|
||||
};
|
||||
|
||||
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 (
|
||||
!is_on_same_host || // external link
|
||||
target_element.getAttribute("onclick") || // has a handler
|
||||
e.ctrlKey ||
|
||||
e.metaKey || // open in a new tab
|
||||
|
|
@ -53,18 +54,13 @@ $("body").on("click", "a", function (e) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (href === "") {
|
||||
return override("/app");
|
||||
}
|
||||
|
||||
if (href && href.startsWith("#")) {
|
||||
// target startswith "#", this is a v1 style route, so remake it.
|
||||
return override(target_element.hash);
|
||||
}
|
||||
|
||||
if (is_on_same_host && frappe.router.is_app_route(target_element.pathname)) {
|
||||
if (frappe.router.is_app_route(target_element.pathname)) {
|
||||
// target has "/app, this is a v2 style route.
|
||||
|
||||
if (target_element.search) {
|
||||
frappe.route_options = {};
|
||||
let params = new URLSearchParams(target_element.search);
|
||||
|
|
@ -72,7 +68,10 @@ $("body").on("click", "a", function (e) {
|
|||
frappe.route_options[key] = value;
|
||||
}
|
||||
}
|
||||
return override(target_element.pathname + target_element.hash);
|
||||
if (target_element.hash) {
|
||||
frappe.route_hash = target_element.hash;
|
||||
}
|
||||
return override(target_element.pathname);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -139,6 +138,12 @@ frappe.router = {
|
|||
if (!frappe.app) return;
|
||||
|
||||
let sub_path = this.get_sub_path();
|
||||
if (frappe.boot.setup_complete) {
|
||||
!frappe.re_route["setup-wizard"] && (frappe.re_route["setup-wizard"] = "app");
|
||||
} else if (!sub_path.startsWith("setup-wizard")) {
|
||||
frappe.re_route["setup-wizard"] && delete frappe.re_route["setup-wizard"];
|
||||
frappe.set_route(["setup-wizard"]);
|
||||
}
|
||||
if (this.re_route(sub_path)) return;
|
||||
|
||||
this.current_sub_path = sub_path;
|
||||
|
|
@ -346,8 +351,8 @@ frappe.router = {
|
|||
route = this.get_route_from_arguments(route);
|
||||
route = this.convert_from_standard_route(route);
|
||||
let sub_path = this.make_url(route);
|
||||
// replace each # occurrences in the URL with encoded character except for last
|
||||
// sub_path = sub_path.replace(/[#](?=.*[#])/g, "%23");
|
||||
sub_path += frappe.route_hash || "";
|
||||
frappe.route_hash = null;
|
||||
if (frappe.open_in_new_tab) {
|
||||
localStorage["route_options"] = JSON.stringify(frappe.route_options);
|
||||
window.open(sub_path, "_blank");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue