Skip to content

Commit

Permalink
Merge pull request #110 from solo-io/charlesthebird/apisPageReloadFix
Browse files Browse the repository at this point in the history
Apis Page Reload Fix
  • Loading branch information
jmhbh authored Nov 11, 2024
2 parents f41d72c + 764cb94 commit 6e0054e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog/v0.0.37/api-page-reload-env-var-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
- type: NEW_FEATURE
description: >-
Fixes the API page reload behavior when navigating to it with `VITE_API_PAGE_RELOAD=true`,
so that the React Router behavior is overridden in that case.
18 changes: 14 additions & 4 deletions projects/ui/src/Components/Structure/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useContext, useMemo } from "react";
import { MouseEventHandler, useContext, useMemo } from "react";
import { Link, NavLink, useLocation } from "react-router-dom";
import { ReactComponent as Logo } from "../../Assets/logo.svg";
import { AppContext } from "../../Context/AppContext";
import { AuthContext } from "../../Context/AuthContext";
import {apiPageReload, logoImageURL} from "../../user_variables.tmplr";
import { apiPageReload, logoImageURL } from "../../user_variables.tmplr";
import { ErrorBoundary } from "../Common/ErrorBoundary";
import { HeaderStyles } from "./Header.style";
import HeaderSectionLoggedIn from "./HeaderSectionLoggedIn";
Expand All @@ -17,6 +17,17 @@ if (!window.isSecureContext) {
);
}

// If apiPageReload is true use the onclick to reload the page
export const onApisPageClick: MouseEventHandler<HTMLAnchorElement> | undefined =
apiPageReload === "true"
? (e) => {
// If we are using `apiPageReload=true`, we want to override the react router
// behavior here, otherwise we get 2 `/apis` page history entries.
e.preventDefault();
window.location.href = "/apis";
}
: undefined;

/**
* MAIN COMPONENT
**/
Expand Down Expand Up @@ -89,8 +100,7 @@ export function Header() {
*/}
<NavLink
to={"/apis"}
// if apiPageReload is true use the onclick to reload the page
onClick={apiPageReload === "true" ? () => (window.location.href = "/apis") : undefined}
onClick={onApisPageClick}
className={`navLink ${inAPIsArea ? "active" : ""}`}
>
APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Link, NavLink, useLocation } from "react-router-dom";
import { ReactComponent as Logo } from "../../../Assets/logo.svg";
import { AppContext } from "../../../Context/AppContext";
import { ErrorBoundary } from "../../Common/ErrorBoundary";
import { onApisPageClick } from "../Header";
import { HeaderStyles } from "../Header.style";
import { OidcAuthCodeHeaderDropdown } from "./OidcAuthCodeHeaderDropdown";
import {apiPageReload} from "../../../user_variables.tmplr";

/**
* This is for when there is an
Expand Down Expand Up @@ -37,7 +37,7 @@ const OidcAuthCodeHeaderVariant = () => {
</NavLink>
<NavLink
to={"/apis"}
onClick={apiPageReload === "true" ? () => (window.location.href = "/apis") : undefined}
onClick={onApisPageClick}
className={`navLink ${inAPIsArea ? "active" : ""}`}
>
APIs
Expand Down

0 comments on commit 6e0054e

Please sign in to comment.