forked from aeharding/voyager
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActorRedirect.tsx
26 lines (21 loc) · 898 Bytes
/
ActorRedirect.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Redirect, useLocation, useParams } from "react-router";
import { useAppSelector } from "./store";
import { jwtIssSelector } from "./features/auth/authSlice";
import React from "react";
import UseIonViewIsVisible from "./helpers/useIonViewIsVisible";
interface ActorRedirectProps {
children?: React.ReactNode;
}
export default function ActorRedirect({ children }: ActorRedirectProps) {
const { actor } = useParams<{ actor: string }>();
const iss = useAppSelector(jwtIssSelector);
const location = useLocation();
const ionViewIsVisible = UseIonViewIsVisible();
if (!ionViewIsVisible) return <>{children}</>;
if (!iss || !actor) return <>{children}</>;
if (iss === actor) return <>{children}</>;
const [first, second, _wrongActor, ...urlEnd] = location.pathname.split("/");
return (
<Redirect to={[first, second, iss, ...urlEnd].join("/")} push={false} />
);
}