0

My App is working perfectly on http://localhost:3000/ but when I try to run it on Netlify (https://famous-swan-6a778d.netlify.app/) the homepage loads correctly, but when I try to go to some other page it shows the Page Not Found error.

My routing is set up as:

import { BrowserRouter as Router, Route, Routes } from "react-router-dom";

import Dashboard from "./components/Dashboard";
import EncryptedMessage from "./components/EncryptedMessage";
import NotFound from "./components/NotFound";
import Navbar from "./components/Navbar";

function App() {
  return (
    <Router>
      <Navbar />
      <Routes>
        <Route path="/" element={<Dashboard />}></Route>
        <Route
          path="/messages/:uniqueId"
          element={<EncryptedMessage />}
        ></Route>
        <Route path="*" element={<NotFound />}></Route>
      </Routes>
    </Router>
  );
}

export default App;

The / is working perfectly, but when I try to go to say https://famous-swan-6a778d.netlify.app/messages/123/ , it throws an error but if I go to http://localhost:3000/messages/123/ , it's working fine.

How do I fix this?

0

2 Answers 2

1

To prevent PAGE NOT FOUND error from netlify app:-

Make a file inside public named as _redirects. Inside it write a line of code 👇

/*    /index.html    200
Sign up to request clarification or add additional context in comments.

Comments

0

Turns out that strict mode was causing this problem. You can disable it in your index.js file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.