Skip to content

Commit ef6fc21

Browse files
committed
pat-inject: Improve code for updating the history object.
1 parent a28a386 commit ef6fc21

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/pat/inject/inject.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,22 +468,20 @@ const inject = {
468468

469469
_update_history(cfg, trigger, title) {
470470
// History support. if subform is submitted, append form params
471-
const glue = cfg.url.indexOf("?") > -1 ? "&" : "?";
472-
if (cfg.history === "record" && "pushState" in history) {
473-
if (cfg.params) {
474-
history.pushState(
475-
{ url: cfg.url + glue + cfg.params },
476-
"",
477-
cfg.url + glue + cfg.params
478-
);
479-
} else {
480-
history.pushState({ url: cfg.url }, "", cfg.url);
481-
}
482-
// Also inject title element if we have one
483-
if (title)
484-
this._inject(trigger, title, $("title"), {
485-
action: "element",
486-
});
471+
if (cfg.history !== "record" || !history?.pushState) {
472+
return;
473+
}
474+
let url = cfg.url;
475+
const glue = url.indexOf("?") > -1 ? "&" : "?";
476+
if (cfg.params) {
477+
url = `${url}${glue}${cfg.params}`;
478+
}
479+
history.pushState({ url: url }, "", url);
480+
// Also inject title element if we have one
481+
if (title) {
482+
this._inject(trigger, title, $("title"), {
483+
action: "element",
484+
});
487485
}
488486
},
489487

0 commit comments

Comments
 (0)