Skip to content

Commit

Permalink
Merge pull request #601 from open-formulieren/fix/hash-base-routing-p…
Browse files Browse the repository at this point in the history
…roblem

⚗️ Attempt hot-fix for hash based routing
  • Loading branch information
sergei-maertens authored Dec 5, 2023
2 parents 9b50efa + 406e53a commit 4576485
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ class OpenForm {
CSPNonce.setValue(CSPNonceValue);
initialiseSentry(sentryDSN, sentryEnv);

// ensure that the basename has no trailing slash (for react router)
let pathname = basePath || window.location.pathname;
if (pathname.endsWith('/')) {
pathname = pathname.slice(0, pathname.length - 1);
if (useHashRouting) {
this.basePath = '';
} else {
// ensure that the basename has no trailing slash (for react router)
let pathname = basePath || window.location.pathname;
if (pathname.endsWith('/')) {
pathname = pathname.slice(0, pathname.length - 1);
}
this.basePath = pathname;
}
this.basePath = pathname;

this.calculateClientBaseUrl();
}

Expand Down
2 changes: 1 addition & 1 deletion src/sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ describe('OpenForm', () => {
useHashRouting: true,
});

expect(form.clientBaseUrl).toEqual('http://localhost/some-server-side/path#/some-subpath');
expect(form.clientBaseUrl).toEqual('http://localhost/some-server-side/path#/');
});
});

0 comments on commit 4576485

Please sign in to comment.