Skip to content

Commit

Permalink
fix: redirect to /targets when going to /
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Aug 23, 2023
1 parent 9f45892 commit 383a90c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/webui/ui/src/components/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createHashRouter, useRouteError } from "react-router-dom";
import { createHashRouter, useNavigate, useRouteError } from "react-router-dom";
import App from "./App";
import { TargetsView } from "./targets-view/TargetsView";
import { ErrorMessageCard } from "./ErrorMessage";
import { Box } from "@mui/material";
import React, { useEffect } from "react";

function ErrorPage() {
const error = useRouteError() as any;
Expand All @@ -13,12 +14,25 @@ function ErrorPage() {
</ErrorMessageCard>
}

function Redirect(props: { to: string }) {
let navigate = useNavigate();
useEffect(() => {
navigate(props.to, {replace: true});
});
return null;
}

export const Router = createHashRouter([
{
path: "/",
element: <App />,
errorElement: <ErrorPage />,
children: [
{
path: "/",
element: <Redirect to={"/targets"}/>,
errorElement: <ErrorPage />,
},
{
path: "targets/*",
element: <TargetsView />,
Expand Down

0 comments on commit 383a90c

Please sign in to comment.