element-call/src/room/RoomRedirect.jsx

26 lines
688 B
React
Raw Normal View History

2022-01-05 23:06:51 +00:00
import React, { useEffect } from "react";
import { useLocation, useHistory } from "react-router-dom";
2022-01-06 01:19:03 +00:00
import { defaultHomeserverHost } from "../matrix-utils";
2022-01-05 23:06:51 +00:00
import { LoadingView } from "../FullScreenView";
export function RoomRedirect() {
const { pathname } = useLocation();
const history = useHistory();
useEffect(() => {
let roomId = pathname;
if (pathname.startsWith("/")) {
2022-02-14 20:35:39 +00:00
roomId = roomId.substring(1, roomId.length);
2022-01-05 23:06:51 +00:00
}
if (!roomId.startsWith("#") && !roomId.startsWith("!")) {
roomId = `#${roomId}:${defaultHomeserverHost}`;
}
history.replace(`/room/${roomId.toLowerCase()}`);
2022-01-05 23:06:51 +00:00
}, [pathname, history]);
return <LoadingView />;
}