import { useRouteMatch } from 'react-router' ; import { useRef } from 'react' ; import { StickyCluster } from 'teleport/types' ; import cfg from 'teleport/config' ; export default function useStickyClusterId ( ) { const stickyCluster = useRef ( { clusterId : cfg . proxyCluster , hasClusterUrl : false , isLeafCluster : false , } ) ; const match = useRouteMatch < { clusterId : string ; } > ( cfg . routes . cluster ) ; const clusterId = match ?. params ?. clusterId ; if ( clusterId ) { stickyCluster . current . clusterId = clusterId ; stickyCluster . current . isLeafCluster = clusterId !== cfg . proxyCluster ; } stickyCluster . current . hasClusterUrl = ! ! clusterId ; return stickyCluster . current ; }