我正在尝试显示两个不同的导航栏组件,一个作为主站点导航栏,一个用于仪表板导航栏。
我尝试创建两个可重用的组件,即:
<LayoutNav />
和<DashboardNav />
这是他们的实现:
const LayoutNav = ({children}) => {
return (
<>
<section className="container-fluid">
<Navbar />
{children}
</section>
</>
);
}
这是相同的,LayoutDashboardNav
我只更改<Navbar />
为<DashboardNav />
以下是我的路线实现:
<BrowserRouter>
<Switch>
<LayoutNav>
<Route exact path="/registervehicle" component={RegVehicle} />
<Route exact path="/result" component={SearchResults} />
<Route exact path="/selectseat" component={PickSeat} />
<Route exact path="/forgotpassword" component={ForgotPassword} />
<Route exact path="/resetpassword" component={ResetPassword} />
<Route exact path="/register" component={Registration} />
<Route exact path="/login" component={LoginAuth} />
<Route exact path="/" component={Home} />
</LayoutNav>
<LayoutDashboardNav>
<Route exact path="/companydashboard" component={CompanyDashboard} />
</LayoutDashboardNav>
<Route component={NotFound} />
</Switch>
<Footer />
</BrowserRouter>
我希望看到<Navbar />
或<DashboardNav />
仅在那些是它们所用组件的子级的页面上看到。但一切都只显示<Navbar />
。