1

I am new to react development and after i deployed my react project on github pages when i visit the url https://tevfik94.github.io/social_app/ i am facing this issue Unhandled Thrown Error! 404 Not Found Hey developer

You can provide a way better UX than this when your app throws errors by providing your own errorElement props on <Route>

so how i can fix this issue

import Login from "./pages/login/Login";
import Register from "./pages/register/Register";
import {
  createBrowserRouter,
  RouterProvider,
  Outlet,
  Navigate,
} from "react-router-dom";
import NavBar from "./components/navBar/NavBar";
import LeftBar from "./components/leftBar/LeftBar";
import RightBar from "./components/rightBar/RightBar";
import Home from "./pages/home/Home";
import Profile from "./pages/profile/Profile";
import "./style.scss";
import { DarkModeContext } from "./context/darkModeContext";
import { useContext } from "react";
import { AuthContext } from "./context/authContext";

function App() {
  const { currentUser } = useContext(AuthContext);
  const { darkMode } = useContext(DarkModeContext);

  const Layout = () => {
    return (
      <div className={`theme-${darkMode ? "dark" : "light"}`}>
        <NavBar />
        <div style={{ display: "flex" }}>
          <LeftBar />
          <div style={{ flex: 6 }}>
            <Outlet />
          </div>

          <RightBar />
        </div>
      </div>
    );
  };

  const ProtectedRoute = ({ children }) => {
    if (!currentUser) {
      return <Navigate to="/login" />;
    }
    return children;
  };

  const router = createBrowserRouter([
    {
      path: "/",
      element: (
        <ProtectedRoute>
          <Layout />
        </ProtectedRoute>
      ),
      children: [
        {
          path: "/",
          element: <Home />,
        },
        {
          path: "/profile/:id",
          element: <Profile />,
        },
      ],
    },
    {
      path: "/login",
      element: <Login />,
    },
    {
      path: "/register",
      element: <Register />,
    },
  ]);
  return (
    <div className="App">
      <RouterProvider router={router} />
    </div>
  );
}

export default App;
I tried to publish the same project on netlify and it works correctly
Drew Reese
  • 165,259
  • 14
  • 153
  • 181
Tevfik
  • 37
  • 5
  • Github hosting works a little differently, and generally isn't compatible with `BrowserRouter`s, you'll instead likely need to use a `HashRouter` component. Does this help answer your question? https://stackoverflow.com/a/71985764/8690857 – Drew Reese Nov 30 '22 at 23:46

0 Answers0