I am making a single page website. I added the Bootstrap navbar to Menu.js using React Router but once I add the menu.js to App.js the website becomes blank. Besides the links are not working. They are supposed to jump to the given component on the same page.
Here is my code for App.js
import "./App.css";
import "./components/Introduction";
import Menu from "./components/Menu";
import Introduction from "./components/Introduction";
import Team from "./components/Team";
import Products from "./components/Products";
import Contact from "./components/Contact";
import BackgroundImage from "./components/BackgroundImage";
import "bootstrap/dist/css/bootstrap.min.css";
function App() {
return (
<div className="App">
<Menu />
<BackgroundImage />
<div className="container titel text-center">
<h1>Titel</h1>
<h2>
<em>Subtitle</em>
</h2>
</div>
<Introduction />
<Products />
<Team />
<Contact />
</div>
);
}
export default App;
Here is my code for Menu.js (Navbar)
import React from "react";
import "./Menu.css";
import { Navbar, Nav, Container } from "react-bootstrap";
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";
import Introduction from "./Introduction";
import Team from "./Team";
import Products from "./Products";
import Contact from "./Contact";
import App from "../App";
function Menu() {
return (
<Router>
<Navbar bg="light" expand="lg">
<Container>
<Navbar.Brand as={Link} to={"/"}>
React-Bootstrap
</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="me-auto">
<Nav.Link as={Link} to={"/introduction"}>
Introduction
</Nav.Link>
<Nav.Link as={Link} to={"/products"}>
Products
</Nav.Link>
<Nav.Link as={Link} to={"/team"}>
Team
</Nav.Link>
<Nav.Link as={Link} to={"/contact"}>
Contact
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
<Routes>
<Route exact path="/">
<App />
</Route>
<Route path="/introduction">
<Introduction />
</Route>
<Route path="/products">
<Products />
</Route>
<Route path="/team">
<Team />
</Route>
<Route path="/contact">
<Contact />
</Route>
</Routes>
</Router>
);
}
export default Menu;
I had to use Routes instead of Switch (error message). I tried to add the code between Routes to index.js and also to App.js. But none of them worked.