javascript - React Router 在 else 中加载任何一个组件
问题描述
我创建了一个带有受保护路由的反应应用程序。现在应用程序在舞台上我无法对其进行任何强烈的更改。事情在我的App.js
组件中,我有一个条件
<div className="App">
{
(props.auth) ? <MainView /> : <Signin />
}
</div>
MainView
组件中写入了所有路由。并且props.auth
是redux状态。这工作正常,没有任何挑战。但是现在我想使用SignUp
在用户想要创建帐户时或如果用户想要创建帐户时呈现的组件。但我提到我的路线是用MainView
组件编写的。因此,如果我填写 singup 路线,我只会看到<SignIn>
组件,因为app.js
. 我如何<SignUp>
在不更改更多结构或更简单的方式的情况下调用组件。
更加具体
<div className="App">
{
(props.auth) ? <MainView /> : <Signin /> || <SignUp /> //I want to render both of them if user not logged in. And they both are seperate component.
}
</div>
解决方案
然后包装在反应片段或 div 中。
<div className="App">
{
(props.auth) ? <MainView /> : <> <Signin /> <SignUp /> </>
}
推荐阅读
- javascript - 检测来自 React 应用程序和 React 组件外部的 html 元素的点击
- git - Gitlab 显示 repo 已更新
- unit-testing - 单元测试以在响应数组中查找关键字
- bash - Kerberos klist 未显示票证
- java - 为什么我可以在没有设置 JAVA_HOME 的情况下使用 javac 和 java?
- asp.net-core - .net 5 响应返回文本和数字
- php - 在 PHP 中使用 CURL 发布 JSON 正文
- flutter - 使用图像的 Flutter 圆形进度指示器
- ios - 如何在 Go 中验证应用商店服务器 api 的 JWS 事务
- snakemake - 多个用户执行相同的工作流程