Skip to content

Commit 79af45f

Browse files
aurreco-ugaCristina Aurrecoechea
andauthored
homepage-tiles-correcturl-and-redirectincorrect second attempt (#1538)
Co-authored-by: Cristina Aurrecoechea <aurreco@palm.penn.apidb.org>
1 parent 574b488 commit 79af45f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/libs/web-common/src/bootstrap.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function initialize(options = {}) {
6969
additionalMiddleware,
7070
} = options;
7171

72+
fixURLSlashHash();
7273
fixForwardSlashes();
7374
unaliasWebappUrl();
7475
removeJsessionid();
@@ -104,6 +105,16 @@ export function initialize(options = {}) {
104105
return context;
105106
}
106107

108+
// home page tiles: redirect incorrect urls provided to users /app/#funding to correct /app#funding,
109+
export function fixURLSlashHash() {
110+
const { pathname, hash } = window.location;
111+
if (hash && pathname.endsWith('/')) {
112+
const newPathname = (pathname + '/').replace(/[/]+/g, '/').slice(0, -1);
113+
const newUrl = `${window.location.origin}${newPathname}${window.location.search}${hash}`;
114+
window.history.replaceState(null, '', newUrl);
115+
}
116+
}
117+
107118
function fixForwardSlashes() {
108119
const { pathname } = window.location;
109120
if (pathname.includes('//') || pathname.endsWith('/')) {
@@ -113,7 +124,7 @@ function fixForwardSlashes() {
113124
}
114125

115126
/**
116-
* Replace apache alaias `/a` with the webapp url.
127+
* Replace apache alias `/a` with the webapp url.
117128
*/
118129
function unaliasWebappUrl() {
119130
if (rootUrl) {

packages/libs/web-common/src/components/homepage/FeaturedTools.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { useSessionBackedState } from '@veupathdb/wdk-client/lib/Hooks/SessionBa
1717
import { makeClassNameHelper } from '@veupathdb/wdk-client/lib/Utils/ComponentUtils';
1818
import { decode, string } from '@veupathdb/wdk-client/lib/Utils/Json';
1919

20+
import { fixURLSlashHash } from '../../bootstrap.js';
21+
2022
import './FeaturedTools.scss';
2123
import { ContentError } from './ContentError';
2224

@@ -332,6 +334,7 @@ const ToolListItem = ({ entry, onSelect, isSelected }: ToolListItemProps) => {
332334
e.preventDefault();
333335
onSelect();
334336
history.replace(`#${entry.identifier}`);
337+
fixURLSlashHash();
335338
}}
336339
type="button"
337340
>

0 commit comments

Comments
 (0)