0

I am trying to finish my personal portfolio site that I am building with vite Reactjs, I am having trouble with react-router-dom, I have some components, most of them on a single page but I wanted to try Router, so I tried to implement it with About component, but its kinda working in local host and shows "page not found" on live lite when I click on about!! Live Site Error. [My site][https://mjshubham21.live/]

I tried quite a few things with Routes, but it keeps breaking and the live site err, "Page not found" persists!!

//My App component:
import React from "react";
import NavBar from "./NavBar";
import Intro from "./Intro";
import About from "./About";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

  return (
    <>
      <Router>
        <Routes>
          <Route exact path="/" element={<NavBar />}></Route>
          <Route exact path="/about" element={<About />}></Route>
        </Routes>
        <Intro />
      </Router>
    </>
  );
}

export default App; //I only kept related components here.

//My NavBar component:
import React from "react";
import { Link } from "react-router-dom";
function NavBar() {
  return (
    <>
      <nav>
        <div className="itemL">
          <Link to="#">mjshubham21</Link>
        </div>
        <div className="itemR">
          <ul>
            <li>
              <Link to="#">Home</Link>
            </li>
            <li>
              <Link to="/about" target="_blank">
                About Me
              </Link>
            </li>
          </ul>
        </div>
      </nav>
    </>
  );
}

export default NavBar;```
Drew Reese
  • 165,259
  • 14
  • 153
  • 181
mjshubham21
  • 77
  • 1
  • 7
  • are your other routes working and only particular one does not? – Y U K I M U R A Feb 13 '23 at 13:05
  • Shri Hari, it didn't... I have hosted it on Netlify but instead of cra I used vite... – mjshubham21 Feb 13 '23 at 13:08
  • goga... I only wanted About component as a route, In the local host when I click on about, it opens in a new tab and I have some lorem ipsum dummy words for testing which shows up but along with all other components... – mjshubham21 Feb 13 '23 at 13:11
  • I think it's got something to do with the Routes in App component and with "Link, to" in the NavBar component... – mjshubham21 Feb 13 '23 at 13:14
  • [Here's the code sandbox to the whole thing](https://codesandbox.io/p/github/mjshubham21/Mjshubham21Portfolio/draft/quizzical-platform?workspaceId=fe256bc6-8c9b-4e90-91aa-223661878145) – mjshubham21 Feb 13 '23 at 13:19
  • mjshubham21.live - My live site. Not yet responsive... Nav in mobile is currently hidden. When we click on about we get page not found. – mjshubham21 Feb 13 '23 at 13:23
  • Check the CRA [deployment docs](https://create-react-app.dev/docs/deployment/#netlify) for netlify and ensure you have correctly configured the server to host your React app. – Drew Reese Feb 13 '23 at 17:03
  • Drew I used Vite instead of CRA, and I hosted it by choosing my git repository instead of netlify-cli... Did you spot anything wrong in the code in the above link, the code sandbox complete project...? – mjshubham21 Feb 14 '23 at 13:45

0 Answers0