【发布时间】:2021-09-12 07:54:16
【问题描述】:
在我的 react 应用程序中,我使用 react router 进行路由,而在我的应用程序中,我不想为 login page, create account page, etc. 等某些路由呈现导航栏。此外,当用户输入一个不存在的路由时,它应该呈现一个 404 页面。
我该怎么做?为了呈现这样的页面,我必须做什么样的安排。在当前设置下,它正在渲染 404 页面以及 login and register pages。
我该如何解决这个问题?
{/* Routes Without Nav */}
<Switch>
<Route exact path="/login">
<Login notify={setResMessage} />
</Route>
<Route exact path="/user/create">
<CreateAc notify={setResMessage} />
</Route>
<Route exact path="/mobile/search">
<MobileSearchPage notify={setResMessage} />
</Route>
<Navbar notify={setResMessage} />
</Switch>
<Switch>
{/* Routes With Nav */}
<Route exact path="/">
<Home notify={setResMessage} />
<Footer />
</Route>
<Route exact path="/cart">
<Cart />
</Route>
<Route exact path="/product/:productID">
<ProductDetails notify={setResMessage} />
</Route>
<Route exact path="/search/:product">
<SearchPage notify={setResMessage} />
</Route>
<Route exact path="/payment-success">
<PaymentSuccess />
</Route>
<Route exact path="/recommended">
<Recommendations />
</Route>
{/* ----------------Not So IMP Routes---------------- */}
<Route exact path="/create-product" component={AddProduct} />
<Route component={PageNotFound} />
</Switch>
【问题讨论】:
标签: reactjs react-router react-router-dom