// Navigation helpers import { ipcRenderer } from "electron"; import { reaction } from "mobx"; import { matchPath, RouteProps } from "react-router"; import { createObservableHistory } from "mobx-observable-history"; import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history"; import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc"; import { PageParam, PageParamInit } from "./page-param"; import { clusterViewRoute, IClusterViewRouteParams } from "../components/cluster-manager/cluster-view.route"; import logger from "../../main/logger"; export let history = ipcRenderer ? createBrowserHistory() : createMemoryHistory(); export let navigation = createObservableHistory(history); export function navigate(location: LocationDescriptor) { const currentLocation = navigation.getPath(); navigation.push(location); if (currentLocation === navigation.getPath()) { navigation.goBack(); // prevent sequences of same url in history } } export function matchParams
(route: string | string[] | RouteProps) { return matchPath
(navigation.location.pathname, route);
}
export function isActiveRoute(route: string | string[] | RouteProps): boolean {
return !!matchParams(route);
}
export function getMatchedClusterId(): string {
const matched = matchPath