From 12f2aded2257a7dcc9dbb00cbbd8bafc28579ad4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 09:23:02 -0500 Subject: navigate on tab click, set initial tab with redirect --- src/web/src/components/System/System.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index ac6f5dfd..ca88c50d 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -1,5 +1,5 @@ import React from 'react'; -import { useRouteMatch } from "react-router-dom"; +import { useRouteMatch, useHistory, Redirect } from "react-router-dom"; import { Segment, Tab } from 'semantic-ui-react'; @@ -10,7 +10,8 @@ import Logs from './Logs'; import Options from './Options'; const System = ({ state = {}, options = {} }) => { - const { params: { tab }} = useRouteMatch(); + const { params: { tab }, ...route } = useRouteMatch(); + const history = useHistory(); const panes = [ { route: 'info', menuItem: 'Info', render: () => }, @@ -20,12 +21,21 @@ const System = ({ state = {}, options = {} }) => { const activeIndex = panes.findIndex(pane => pane.route === tab) + const onTabChange = (e, { activeIndex }) => { + history.push(panes[activeIndex].route) + } + + if (tab === undefined) { + return + } + return (
-1 ? activeIndex : 0} panes={panes} + onTabChange={onTabChange} />
-- cgit v1.2.3