From 9901bf340019d431c1aaba69546589e73ccbd8f3 Mon Sep 17 00:00:00 2001 From: LASER-Yi Date: Fri, 3 Sep 2021 09:35:46 +0800 Subject: [PATCH] Fix redirect issues when accessing root path --- frontend/src/Navigation/RootRedirect.tsx | 19 +++++++++++++++++++ frontend/src/Navigation/index.ts | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 frontend/src/Navigation/RootRedirect.tsx diff --git a/frontend/src/Navigation/RootRedirect.tsx b/frontend/src/Navigation/RootRedirect.tsx new file mode 100644 index 000000000..eec9a335d --- /dev/null +++ b/frontend/src/Navigation/RootRedirect.tsx @@ -0,0 +1,19 @@ +import { FunctionComponent } from "react"; +import { Redirect } from "react-router-dom"; +import { useIsRadarrEnabled, useIsSonarrEnabled } from "../@redux/hooks"; + +const RootRedirect: FunctionComponent = () => { + const sonarr = useIsSonarrEnabled(); + const radarr = useIsRadarrEnabled(); + + let path = "/settings"; + if (sonarr) { + path = "/series"; + } else if (radarr) { + path = "movies"; + } + + return ; +}; + +export default RootRedirect; diff --git a/frontend/src/Navigation/index.ts b/frontend/src/Navigation/index.ts index ee9e6d559..dbcb4db6a 100644 --- a/frontend/src/Navigation/index.ts +++ b/frontend/src/Navigation/index.ts @@ -37,6 +37,7 @@ import SystemTasksView from "../System/Tasks"; import WantedMoviesView from "../Wanted/Movies"; import WantedSeriesView from "../Wanted/Series"; import { Navigation } from "./nav"; +import RootRedirect from "./RootRedirect"; export function useNavigationItems() { const sonarr = useIsSonarrEnabled(); @@ -51,6 +52,12 @@ export function useNavigationItems() { component: EmptyPage, routeOnly: true, }, + { + name: "Redirect", + path: "/", + component: RootRedirect, + routeOnly: true, + }, { icon: faPlay, name: "Series",