Fix ChannelSelect routing

This commit is contained in:
Ingo Oppermann 2022-11-10 13:45:02 +01:00
parent 3a5a91c2c9
commit 4ec02d1b2d
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
2 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import React from 'react';
import { Route, Navigate, Routes, HashRouter } from 'react-router-dom';
import { Route, Navigate, Routes, HashRouter as DOMRouter } from 'react-router-dom';
import Views from './views';
@ -11,9 +11,9 @@ export default function Router(props) {
const channelid = props.restreamer.GetCurrentChannelID();
return (
<HashRouter>
<DOMRouter>
<Routes>
<Route path="/" element={<Views.ChannelSelect restreamer={props.restreamer} />} />
<Route path="/" element={<Views.ChannelSelect channelid={channelid} />} />
<Route path="/playersite" element={<Views.Playersite restreamer={props.restreamer} />} />
<Route path="/settings" element={<Views.Settings restreamer={props.restreamer} />} />
<Route path="/settings/:tab" element={<Views.Settings restreamer={props.restreamer} />} />
@ -26,7 +26,7 @@ export default function Router(props) {
<Route path="/:channelid/publication/:service/:index" element={<Views.EditService key={channelid} restreamer={props.restreamer} />} />
<Route path="*" render={() => <Navigate to="/" replace />} />
</Routes>
</HashRouter>
</DOMRouter>
);
}

View File

@ -3,17 +3,24 @@ import { useNavigate } from 'react-router-dom';
export default function ChannelSelector(props) {
const navigate = useNavigate();
const [$channelid, setChannelid] = React.useState('');
React.useEffect(() => {
onMount();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const onMount = () => {
const channelid = props.restreamer.GetCurrentChannelID();
React.useEffect(() => {
navigate(`/${$channelid}`, { replace: true });
}, [navigate, $channelid]);
navigate(`/${channelid}`, { replace: true });
const onMount = () => {
setChannelid(props.channelid);
};
return null;
}
ChannelSelector.defaultProps = {
channelid: '',
};