New to React. I have a React component Navbar.js
that will display in 3 pages : Landing, Login and Home but with different tabs in each page.
For example, it will display a login button tab in the landing but will hide in login page and in the home page it will display a search box and logout button.
I tried to hide the menu icon when going from the landing page to the login page by testing on the URL:
const opendrawer = (
<IconButton
className={classes.menuButton}
color="inherit"
aria-label="Open drawer"
>
<MenuIcon />
</IconButton>
);
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
{window.location.href.includes("/login") ? null : opendrawer}
</div>
</Toolbar>
</AppBar>
After trying this the menu icon did hide but only when I refresh the page manually.
You can use props to this, create a constant informing which elements you want to render this specific icon. I did something similar on my application, I wanted to render a bottom bar only in some pages:
App.js
Canvas.js