每页内容相同

Same content on every page

如何在不同的页面上显示不同的内容?我使用 app.js 作为主页,第二页使用联系人,但无论我在 App.js 中做了什么更改,更改都会显示在联系人上。我该如何解决这个问题?

谢谢大家

App.js:

import React from "react";
    import {
      BrowserRouter as Router,
      Navigate,
      Route,
      Routes,
      Link
    } from "react-router-dom";
    import './App.css';
    import NavigationBar from "./components/NavigationBar";
    import Hero from "./components/NavigationBar/Hero/Hero";
    import Contact from "./components/Contact"
    import ErrorPage from "./components/ErrorPage";
    import { authentication } from "./firebase";
    import { signInWithPopup, GoogleAuthProvider } from "firebase/auth";
    import SignUpForm from "./components/SignUpForm"
    
      const signInWithGoogle = ()=>{
        const provider = new GoogleAuthProvider();
        signInWithPopup(authentication, provider)
        .then((re)=>{
          console.log(re)
        })
        .catch((err)=>{
          console.log(err)
        })
      }
    const App = () => {
      return (
    <div className="App">
      <Hero />
   <Router>
    <NavigationBar />
     <Routes>
       <Route index path="/"/>
       <Route path="/contact" element={<Contact />} />
       <Route path="/signupform" element={<SignUpForm />} />
       {/* <Route path="*" element={<Navigate to="/App" replace />} /> */}
        {/* <Route path="*" element={ErrorPage}/> */}
     </Routes>
   </Router>
   <button onClick={signInWithGoogle}>
   </button>
   </div> 
  );
}

export default App;

您可以使用 React Router to specify which content is displayed on which URL. The tutorial can be found here.

例如:

import { render } from "react-dom";
import {
  BrowserRouter,
  Routes,
  Route,
} from "react-router-dom";
import App from "./App";
import Expenses from "./routes/expenses";
import Invoices from "./routes/invoices";

const rootElement = document.getElementById("root");
render(
  <BrowserRouter>
    <Routes>
      <Route path="/" element={<App />} />
      <Route path="expenses" element={<Expenses />} />
      <Route path="invoices" element={<Invoices />} />
    </Routes>
  </BrowserRouter>,
  rootElement
);