Remove all but cluster url param when navigating

This commit is contained in:
Justin Starry 2020-06-03 18:49:33 +08:00 committed by Michael Vines
parent d5421266f5
commit 03f7d28aff
3 changed files with 23 additions and 2 deletions

View File

@ -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() {
<div className="container">
<div className="row align-items-end">
<div className="col">
<Link to={location => ({ ...location, pathname: "/" })}>
<Link
to={location => ({ ...pickCluster(location), pathname: "/" })}
>
<img src={Logo} width="250" alt="Solana Explorer" />
</Link>
</div>

View File

@ -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 (
<Link
to={location => ({ ...location, pathname: href })}
to={location => ({ ...pickCluster(location), pathname: href })}
className={classes}
>
{tab}

View File

@ -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 = [];