admin管理员组文章数量:1387334
(I'm using React - Class Component)
I'm looking for how to remove Footer ponent only in specific page, but i have no idea. Actually I don't have no idea about what keyword to search.
Below code is my Router.js
class Routes extends React.Component {
render() {
return (
<Router>
<Navbar />
<Switch>
<Route exact path="/" ponent={Main}></Route>
<Route exact path="/review" ponent={ReviewPage}></Route>
</Switch>
<Footer />
</Router>
);
}
}
export default Routes;
I put Footer and Navbar Component in router like that because those are always exists in every page. But unfortunately I just found that in ReviewPage, there is NO FOOTER....
How can i remove Footer only in ReviewPage? Please give me hint !
(I'm using React - Class Component)
I'm looking for how to remove Footer ponent only in specific page, but i have no idea. Actually I don't have no idea about what keyword to search.
Below code is my Router.js
class Routes extends React.Component {
render() {
return (
<Router>
<Navbar />
<Switch>
<Route exact path="/" ponent={Main}></Route>
<Route exact path="/review" ponent={ReviewPage}></Route>
</Switch>
<Footer />
</Router>
);
}
}
export default Routes;
I put Footer and Navbar Component in router like that because those are always exists in every page. But unfortunately I just found that in ReviewPage, there is NO FOOTER....
How can i remove Footer only in ReviewPage? Please give me hint !
Share Improve this question asked May 13, 2021 at 12:22 hellohello 1413 silver badges11 bronze badges 2- Perhaps this will help: stackoverflow./questions/65655479/… – Scott Gnile Commented May 13, 2021 at 12:24
-
include the
<Footer />
just inside theMain
ponent and not in theRoutes
ponent ? – VersifiXion Commented May 13, 2021 at 12:27
2 Answers
Reset to default 7You have to use window.location.pathname
.It returns the current url path name. And then you can set a condition as below:
{window.location.pathname !== '/review' && <Footer />}
Solution
class Routes extends React.Component {
render() {
return (
<Router>
<Navbar />
<Switch>
<Route exact path="/" ponent={Main}></Route>
<Route exact path="/review" ponent={ReviewPage}></Route>
</Switch>
{window.location.pathname !== '/review' && <Footer /> }
</Router>
);
}
}
export default Routes;
{Location.pathname === '/photographer/:id' && }
and you can see new version React-router
Now use Location != location and it works
<>
<Header />
<main>
<Container>
<Routes>
<Route path='/' element={<HomeScreen />}></Route>
<Route
path='/photographer/:id'
element={<PhotographersScreen/>}
></Route>
</Routes>
</Container>
</main>
{Location.pathname === '/photographer/:id' && <Footer />}
</>
本文标签: javascriptHow can I remove Footer Component only in specific pageStack Overflow
版权声明:本文标题:javascript - How can I remove Footer Component only in specific page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744527220a2610815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论