diff --git a/explorer/src/App.tsx b/explorer/src/App.tsx index a2b9455ab0..e55f7299a1 100644 --- a/explorer/src/App.tsx +++ b/explorer/src/App.tsx @@ -12,6 +12,7 @@ import { ACCOUNT_ALIASES, ACCOUNT_ALIASES_PLURAL } from "./providers/accounts"; import TabbedPage from "components/TabbedPage"; import TopAccountsCard from "components/TopAccountsCard"; import SupplyCard from "components/SupplyCard"; +import { pickCluster } from "utils/url"; function App() { return ( @@ -22,7 +23,9 @@ function App() {
- ({ ...location, pathname: "/" })}> + ({ ...pickCluster(location), pathname: "/" })} + > Solana Explorer
diff --git a/explorer/src/components/TabbedPage.tsx b/explorer/src/components/TabbedPage.tsx index 820bf8294f..feb3978786 100644 --- a/explorer/src/components/TabbedPage.tsx +++ b/explorer/src/components/TabbedPage.tsx @@ -2,6 +2,7 @@ import React from "react"; import { Link } from "react-router-dom"; import { useClusterModal } from "providers/cluster"; import ClusterStatusButton from "components/ClusterStatusButton"; +import { pickCluster } from "utils/url"; export type Tab = "Transactions" | "Accounts" | "Supply"; @@ -64,7 +65,7 @@ function NavLink({ return ( ({ ...location, pathname: href })} + to={location => ({ ...pickCluster(location), pathname: href })} className={classes} > {tab} diff --git a/explorer/src/utils/url.ts b/explorer/src/utils/url.ts index 207d0ce646..26cacf1a99 100644 --- a/explorer/src/utils/url.ts +++ b/explorer/src/utils/url.ts @@ -1,9 +1,26 @@ import { useLocation } from "react-router-dom"; +import { Location } from "history"; export function useQuery() { return new URLSearchParams(useLocation().search); } +export function pickCluster(location: Location): Location { + const cluster = new URLSearchParams(location.search).get("cluster"); + + let search = ""; + if (cluster) { + const params = new URLSearchParams(); + params.set("cluster", cluster); + search = params.toString(); + } + + return { + ...location, + search + }; +} + export function findGetParameter(parameterName: string): string | null { let result = null, tmp = [];