diff --git a/src/App.js b/src/App.js
index 573589a..0023877 100644
--- a/src/App.js
+++ b/src/App.js
@@ -29,6 +29,7 @@ import ViewProfile from "./components/Profile/ViewProfile";
import ResetPassword from "./components/Profile/ResetPassword";
import ResetPasswordForm from "./components/Profile/ResetPasswordForm";
import ResetPasswordSent from "./components/Profile/ResetPasswordSent";
+import UrlRedirect from "./components/UrlRedirect";
function App() {
return (
@@ -57,6 +58,7 @@ function App() {
path="reset/sent"
element={}
/>
+ } />
{/* private routes */}
}>
diff --git a/src/components/UrlRedirect.jsx b/src/components/UrlRedirect.jsx
new file mode 100644
index 0000000..f764589
--- /dev/null
+++ b/src/components/UrlRedirect.jsx
@@ -0,0 +1,63 @@
+import React, { useEffect, useState } from "react";
+import { useParams } from "react-router-dom";
+import { Box, Text, Spinner, Flex } from "@chakra-ui/react";
+import axios from "../api/axios";
+
+const UrlRedirect = () => {
+ const { shortCode } = useParams();
+ const [error, setError] = useState(false);
+
+ useEffect(() => {
+ const fetchOriginalUrl = async () => {
+ try {
+ const response = await axios.get(`/url/${shortCode}/`);
+ const { original_url: originalUrl } = response.data;
+ if (originalUrl) {
+ window.location.replace(originalUrl);
+ } else {
+ setError(true);
+ }
+ } catch (err) {
+ console.error("Failed to fetch the URL:", err);
+ setError(true);
+ }
+ };
+
+ fetchOriginalUrl();
+ }, [shortCode]);
+
+ if (error) {
+ return (
+
+
+ URL Not Found
+
+
+ The link you clicked on might be broken, expired, or typed incorrectly.
+
+
+ );
+ }
+
+ return (
+
+
+
+ Redirecting...
+
+
+ );
+};
+
+export default UrlRedirect;