Topic: Using Routes in React

william.yip free asked 6 months ago


I am developing a frontend app with React and trying to use Routes to set up my site structure. It deploys and renders correctly when I deployed it locally, but when using MDB Go, the site is just blank. This is how my App.js looks like:

function App() { return ( < Router> < Routes> < Route path="/" element={} /> < Route path="/about" element={} /> < /Routes> < /Router>

); }


Mateusz Lazaru staff answered 6 months ago


Hi,

This is how it can be configured:

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

function App() {
  return (
    <Router basename="">
      <Routes>
        {" "}
        <Route
          path="/"
          element={
            <div>
              {" "}
              <h1> Home Page </h1>{" "}
            </div>
          }
        />{" "}
        <Route
          path="/about"
          element={
            <div>
              {" "}
              <h1> About Page </h1>
            </div>
          }
        />{" "}
      </Routes>{" "}
    </Router>
  );
}

export default App;

make sure to isntall react-router-dom

npm i react-router-dom


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 8.0.0
  • Device: MacBook Air
  • Browser: Chrome
  • OS: Ventura 13.5
  • Provided sample code: No
  • Provided link: No