Skip to content

Commit 6e0054e

Browse files
authored
Merge pull request #110 from solo-io/charlesthebird/apisPageReloadFix
Apis Page Reload Fix
2 parents f41d72c + 764cb94 commit 6e0054e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
- type: NEW_FEATURE
3+
description: >-
4+
Fixes the API page reload behavior when navigating to it with `VITE_API_PAGE_RELOAD=true`,
5+
so that the React Router behavior is overridden in that case.

projects/ui/src/Components/Structure/Header.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useContext, useMemo } from "react";
1+
import { MouseEventHandler, useContext, useMemo } from "react";
22
import { Link, NavLink, useLocation } from "react-router-dom";
33
import { ReactComponent as Logo } from "../../Assets/logo.svg";
44
import { AppContext } from "../../Context/AppContext";
55
import { AuthContext } from "../../Context/AuthContext";
6-
import {apiPageReload, logoImageURL} from "../../user_variables.tmplr";
6+
import { apiPageReload, logoImageURL } from "../../user_variables.tmplr";
77
import { ErrorBoundary } from "../Common/ErrorBoundary";
88
import { HeaderStyles } from "./Header.style";
99
import HeaderSectionLoggedIn from "./HeaderSectionLoggedIn";
@@ -17,6 +17,17 @@ if (!window.isSecureContext) {
1717
);
1818
}
1919

20+
// If apiPageReload is true use the onclick to reload the page
21+
export const onApisPageClick: MouseEventHandler<HTMLAnchorElement> | undefined =
22+
apiPageReload === "true"
23+
? (e) => {
24+
// If we are using `apiPageReload=true`, we want to override the react router
25+
// behavior here, otherwise we get 2 `/apis` page history entries.
26+
e.preventDefault();
27+
window.location.href = "/apis";
28+
}
29+
: undefined;
30+
2031
/**
2132
* MAIN COMPONENT
2233
**/
@@ -89,8 +100,7 @@ export function Header() {
89100
*/}
90101
<NavLink
91102
to={"/apis"}
92-
// if apiPageReload is true use the onclick to reload the page
93-
onClick={apiPageReload === "true" ? () => (window.location.href = "/apis") : undefined}
103+
onClick={onApisPageClick}
94104
className={`navLink ${inAPIsArea ? "active" : ""}`}
95105
>
96106
APIs

projects/ui/src/Components/Structure/OidcAuthCodeHeaderVariant/OidcAuthCodeHeaderVariant.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Link, NavLink, useLocation } from "react-router-dom";
33
import { ReactComponent as Logo } from "../../../Assets/logo.svg";
44
import { AppContext } from "../../../Context/AppContext";
55
import { ErrorBoundary } from "../../Common/ErrorBoundary";
6+
import { onApisPageClick } from "../Header";
67
import { HeaderStyles } from "../Header.style";
78
import { OidcAuthCodeHeaderDropdown } from "./OidcAuthCodeHeaderDropdown";
8-
import {apiPageReload} from "../../../user_variables.tmplr";
99

1010
/**
1111
* This is for when there is an
@@ -37,7 +37,7 @@ const OidcAuthCodeHeaderVariant = () => {
3737
</NavLink>
3838
<NavLink
3939
to={"/apis"}
40-
onClick={apiPageReload === "true" ? () => (window.location.href = "/apis") : undefined}
40+
onClick={onApisPageClick}
4141
className={`navLink ${inAPIsArea ? "active" : ""}`}
4242
>
4343
APIs

0 commit comments

Comments
 (0)