1+ import { useContext } from 'react' ;
12import {
3+ Navigate ,
4+ generatePath ,
5+ useLocation ,
26 useOutletContext ,
37 useParams ,
48} from 'react-router-dom' ;
9+ import { isDefined } from '@togglecorp/fujs' ;
510
611import { type EmergencyOutletContext } from '#utils/outletContext' ;
712import HtmlOutput from '#components/HtmlOutput' ;
13+ import RouteContext from '#contexts/route' ;
814
915import styles from './styles.module.css' ;
1016
@@ -15,16 +21,39 @@ interface Props {
1521// eslint-disable-next-line import/prefer-default-export
1622export function Component ( props : Props ) {
1723 const urlParams = useParams < { tabId : string } > ( ) ;
24+ const location = useLocation ( ) ;
25+ const routes = useContext ( RouteContext ) ;
1826 const { infoPageId } = props ;
1927 const { emergencyAdditionalTabs } = useOutletContext < EmergencyOutletContext > ( ) ;
2028
2129 const additionalTab = emergencyAdditionalTabs ?. find (
2230 ( tab ) => tab . infoPageId === infoPageId
23- || urlParams . tabId === tab . tabId ,
31+ || urlParams . tabId === tab . tabId
32+ || location . hash === `#${ tab . tabId } ` ,
2433 ) ;
2534
35+ if ( isDefined ( additionalTab ) && `#${ additionalTab . tabId } ` === location . hash ) {
36+ const newPath = generatePath (
37+ // eslint-disable-next-line react/destructuring-assignment
38+ routes . emergencyAdditionalInfo . absoluteForwardPath ,
39+ {
40+ ...urlParams ,
41+ tabId : additionalTab . tabId ,
42+ } ,
43+ ) ;
44+
45+ return (
46+ < Navigate
47+ to = { newPath }
48+ replace
49+ />
50+ ) ;
51+ }
52+
2653 return (
27- < div className = { styles . additionalTab } >
54+ < div
55+ className = { styles . additionalTab }
56+ >
2857 { additionalTab ?. snippets ?. map ( ( snippet ) => (
2958 < HtmlOutput
3059 key = { snippet . id }
0 commit comments