. Advertisement .
..3..
. Advertisement .
..4..
I’m trying to run a new project. I do a couple of things like this:
<Router history={history}>
<Route path="/" component={App}>
<Route path="home component={Home} />
<Route path="about" component={About} />
<Route path="inbox" component={Inbox} />
<Route path="contacts" component={Contacts} />
</Route>
</Router>
<Router history={history}>
<Route path="/" component={App}>
<Route path="home component={Home} />
<Route path="about" component={About} />
{ if.this.props.mail ?
<Route path="inbox" component={Inbox} />
<Route path="contacts" component={Contacts} />
: null }
</Route>
</Router>
But in my program, I am getting the warning:
expressions must have one parent element.
Can someone explain why the “jsx expressions must have one parent element” issue happened? Where have I gone wrong? Thank you!
The cause:
May be you are missing a parent element, so it causes this error. It must be one parent element JSX expression to wrap the elements in the expression which return with one parent element.
Solution:
This error will be solved if you enclose the code after the return statement in an element as
<div>....code </div>
, like below:shorthand fragments can be used to return a list with Logical ‘&&’ Opera for conditional render. It’s very clean. ??? ?