我对React比较陌生,我想知道这里的标准是什么.
想象一下,我有一个像这样的反应路由器:
<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>
Run Code Online (Sandbox Code Playgroud)
现在我想删除两个路由,如果prop.mail设置为false,所以一个明智的方式,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
但是有2条路线和React返回错误:
表达式必须有一个父元素.
我不想在这里使用多个ifs.什么是首选的React处理方式?