Skip to content

Commit

Permalink
🐛 [open-formulieren/open-forms#3362] Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Nov 16, 2023
1 parent ab1020e commit a939e9d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ class OpenForm {
let pathname = this.useHashRouting ? '' : basePath || window.location.pathname;

if (pathname.endsWith('/')) {
// ensure that the basename has no trailing slash (for react router)
// ensure that the pathname has no trailing slash (for react router)
pathname = pathname.slice(0, pathname.length - 1);
}
this.routerBasePath = pathname;
this.basePath = this.useHashRouting ? window.location.pathname : pathname;
this.browserBasePath = this.useHashRouting ? window.location.pathname : pathname;
this.makeRedirect();
this.calculateClientBaseUrl();
}
Expand All @@ -122,7 +122,7 @@ class OpenForm {
action,
actionParams
);
const newUrl = new URL(this.routerBasePath, window.location.origin);
const newUrl = new URL(this.browserBasePath, window.location.origin);
if (!this.useHashRouting) {
newUrl.pathname += `${!newUrl.pathname.endsWith('/') ? '/' : ''}${redirectPath}`;
// We first append query params from the redirect action
Expand All @@ -134,9 +134,6 @@ class OpenForm {
newUrl.searchParams.append(key, val);

Check warning on line 134 in src/sdk.js

View check run for this annotation

Codecov / codecov/patch

src/sdk.js#L134

Added line #L134 was not covered by tests
}
} else {
// We know newUrl.pathname === '/', as this.routerBasePath is '' with hash based routing
newUrl.pathname += window.location.pathname.slice(1);

// First add extra unrelated query params, before hash (`#`)
for (let [key, val] of query.entries()) {
newUrl.searchParams.append(key, val);
Expand All @@ -156,7 +153,7 @@ class OpenForm {
calculateClientBaseUrl() {
// calculate the client-side base URL, as this is recorded in backend calls for
// submissions.
const clientBase = resolvePath(this.basePath).pathname; // has leading slash
const clientBase = resolvePath(this.browserBasePath).pathname; // has leading slash
this.clientBaseUrl = new URL(clientBase, window.location.origin).href;
}

Expand Down

0 comments on commit a939e9d

Please sign in to comment.