Added page-not-found element and improved secured component with replace, and simplified
This commit is contained in:
parent
2f71b7ffc5
commit
719d37c6ee
@ -1,5 +1,5 @@
|
||||
import React, {FC, useEffect} from "react";
|
||||
import {Route, Routes, useNavigate} from "react-router-dom";
|
||||
import React, {FC} from "react";
|
||||
import {Navigate, Route, Routes} from "react-router-dom";
|
||||
import Layout from "./components/layout";
|
||||
import AppRoutes from "./AppRoutes";
|
||||
import "./index.css";
|
||||
@ -23,20 +23,14 @@ export const App: FC = () => (
|
||||
* @param secured Whether or not the page is secured.
|
||||
* @constructor The Secured component.
|
||||
*/
|
||||
const Secured: FC<{ secured: boolean } & ChildProps> = ({children, secured}) => {
|
||||
const Secured: FC<{
|
||||
secured: boolean
|
||||
} & ChildProps> = ({children, secured}) => {
|
||||
const player = useAtomValue(thisPlayerAtom);
|
||||
const navigate = useNavigate();
|
||||
const redirect = secured && player === undefined
|
||||
|
||||
useEffect(() => {
|
||||
if (redirect) {
|
||||
navigate("/login");
|
||||
}
|
||||
});
|
||||
|
||||
if (!redirect) {
|
||||
return (
|
||||
<>{children}</>
|
||||
)
|
||||
if (secured && player === undefined) {
|
||||
return <Navigate to={"/login"} replace/>
|
||||
}
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ const AppRoutes = [
|
||||
{
|
||||
path: "/login",
|
||||
element: <LoginPage/>
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: <p>Page not found</p>
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -52,7 +52,8 @@ public abstract class GenericController : ControllerBase
|
||||
} while (true);
|
||||
|
||||
var disconnectSegment = Disconnect();
|
||||
if (disconnectSegment != null) SendDisconnectMessage((ArraySegment<byte>)disconnectSegment);
|
||||
if (disconnectSegment != null)
|
||||
SendDisconnectMessage((ArraySegment<byte>)disconnectSegment);
|
||||
|
||||
await _webSocketService.Close(WebSocket, result.CloseStatus.Value, result.CloseStatusDescription);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user