A
A
Alexander2018-03-07 10:20:50
React
Alexander, 2018-03-07 10:20:50

React Router how to hide a component?

I'm still new to react and I have a question.
There is always a navigation component on the page, and there is a component of some page of the site, depending on the route. The
question is, for example, when the authorization page component is on the route, hide the navigation component?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
igorianru, 2018-03-07
@igorianru

In theory.
Start a reducer, write a variable there, like isShow: false, do an action, and when initiating a component, check with an action, you can manipulate the display, you will get isShow from the store, when you call the action and pass the display status to it, React will re-render the component itself {this.props.isShown && <Auth />}

A
Anatoly Zharov, 2018-03-07
@SeaBreeze876

!this.props.router.isActive('/login') && <Menu/>
the component needs to be decorated with withRouter()

M
Maxim, 2018-03-07
@maxfarseer

It is possible not to use a router at all. In the component, check the url address natively, and draw the component or not.
Location (MDN)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question