reactjs - 如何将具有条件的两个组件传递给单个路由() 反应 jsx 中的方法?
问题描述
(将带有条件的两个组件传递给反应jsx中的单个路由()方法?
.
解决方案
如果我正确理解你的问题,你只需要添加一个三元表达式。如果条件为真,您将渲染 Component1。如果为 false,您将渲染 Component2。
<Route path="/your_pathname_here">
{condition ? <Component1 /> : <Component2 />}
</Route>
我在这里假设您使用的是 react-router。目前尚不清楚您使用的是什么路由,因为您没有在问题中添加该信息。
推荐阅读
- java - HttpsURLConnection 的默认请求方法
- vue.js - Vue.js 与 v-model 的双向数据绑定
- java - 改进不同类型的 Iterable 的类型检查
- jquery - ASP.NET Core MVC 引导模式 - 改变内容
- javascript - 在 jquery 中停止其他网络请求
- android - 单个命令可在一个视频中裁剪、动画(效果)和添加图像和文本
- search - 输入搜索关键字后使用drupal搜索获取包含在taxonmoy中的节点数
- angular - 在ionic 3中使用打开层单击标记时如何添加信息窗口?
- c# - 根据文本框值自动填充 2 个下拉列表的值
- c# - 将信息用户输入保存到程序中