我有这样的路线:反应路由器使应用程序和登录
<Route path="/" component={App}>
<Route path="login">
<IndexRoute component={LoginPage}/>
</Route>
<Route onEnter={requireAuth}>
<IndexRoute component={DashboardPage} />
<Route path="accounts">
<IndexRoute component={AccountPage}/>
<Route path="add" component={AccountAdd} />
<Route path="detail/:id" component={AccountDetail} />
</Route>
<Route path="contacts">
<Route path="detail/:id" component={ContactPage}/>
</Route>
<Route path="transmissors">
<Route path="detail/:id" component={TransmissorPage}/>
</Route>
<Route path="attends" component={AttendancePage} />
<Route path="reports" component={ReportPage} />
<Route path="configs" component={ConfigurationPage} />
</Route>
</Route>
在我的应用程序组件我想有一个条件来呈现登录页面和应用程序页面。
我不知道如何在我的应用程序有条件。
这里是我的应用程序代码:
class App extends React.Component{
constructor(props) {
super(props);
console.log(this.props.children.type.name);
}
render() {
const loginRender = this.props.children.type.name == "LoginPage";
const appRender = this.props.children.type.name != "LoginPage";
return (
{loginRender(
<div className="app-container">
{this.props.children}
</div>
)}
{appRender(
<div className="app-container">
<Header />
<Sidebar />
<Middle app={this.props.children}/>
</div>
)}
);
}
}
export default App
我不知道,如果使用this.props.children.type.name获得loginpage是最好的方法还是不错的实践。
我想在这里告诉你,如果我得到了 –
我没有收到登录并进入应用页面,我可以编辑我的问题为你尝试帮我吗? –
尝试在每个函数中使用console.log(auth.loggedIn())并查看它返回的内容。还尝试从函数 –