我有三个不同的导航栏。它们中的每一个都是不同的组件。
<PublicNavbar />
,用于公共页面,例如 LandingPage、DiscoverPage 等。<AccessNavbar />
,用于SignInPage、SignUppage、VerificationPage等。<PrivateNavbar />
,用于私人页面,例如 NewCampaignPage 等。
我怎样才能正确地展示它们?如果用户已登录,我想将 DiscoverPage 替换PublicNavbar
为PrivateNavbar
.
import React from "react";
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
import "semantic-ui-css/semantic.min.css";
import "./App.css";
import PublicNavbar from "./components/Navbar/PublicNavbar";
import AccessNavbar from "./components/Navbar/AccessNavbar";
import PrivateNavbar from "./components/Navbar/PrivateNavbar";
import Footer from "./components/Footer";
import LandingPage from "./pages/LandingPage";
import SignIn from "./pages/SIgnInPage";
import DiscoverPage from "./pages/DiscoverPage";
import SignUp from "./pages/SignUpPage";
import Verification from "./pages/VerificationPage";
import Registration from "./pages/RegistrationPage";
import RegistrationComplete from "./pages/RegistrationCompletePage";
import NewCampaign from "./pages/NewCampaignPage";
function App() {
return (
<Router>
<div>
<div id="container">
<div id="main">
<Switch>
<Route path="/" exact component={LandingPage} />
<Route path="/discover" component={DiscoverPage} />
<Route path="/signIn" component={SignIn} />
<Route path="/signUp" component={SignUp} />
<Route path="/verification" component={Verification} />
<Route path="/registration" component={Registration} />
<Route
path="/registration-complete"
component={RegistrationComplete}
/>
<Route path="/new-campaign" component={NewCampaign} />
</Switch>
</div>
</div>
<Footer />
</div>
</Router>
);
}
export default App;
示例导航栏代码:
import React from "react";
const PublicNavbar = () => {
return (
<nav className="navbar navbar-expand-lg bg-white">
<div className="container-fluid navbar-container">
<a className="navbar-brand abs nav-bar-title" href="#">
AshoDaanKori
</a>
<button
className="navbar-toggler ms-auto custom-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#collapseNavbar"
>
<span className="navbar-toggler-icon"></span>
</button>
<div className="navbar-collapse collapse" id="collapseNavbar">
<ul className="navbar-nav ms-auto">
<li className="nav-item active">
<a
className="nav-link"
href=""
data-bs-target="#myModal"
data-bs-toggle="modal"
>
About
</a>
</li>
<li className="nav-item active">
<a
className="nav-link"
href=""
data-bs-target="#myModal"
data-bs-toggle="modal"
>
How it works
</a>
</li>
<li className="nav-item active">
<a
className="nav-link"
href=""
data-bs-target="#myModal"
data-bs-toggle="modal"
>
Discover
</a>
</li>
</ul>
<a
className="nav-link navbar-btn"
href=""
data-bs-target="#myModal"
data-bs-toggle="modal"
>
Start Campaign
</a>
</div>
</div>
</nav>
);
};
export default PublicNavbar;