条件渲染反应路由器v4

时间:2017-04-25 15:07:48

标签: react-router

快速提问?如何在一组组件中共享组件。我想要实现的是在状态设置为未登录时单独使用登录组件。但是,我希望在受保护的客户端路由上有一个应用栏。该文档仅显示如何在 ALL 路由之间共享组件。有人可以帮助我吗?

我的理论代码看起来像这样。

import React, { Component } from "react";
import { Route, Link, Redirect } from "react-router-dom";
import Welcome from "./components/Welcome";
import Login from "./components/Login";
import AuthenticateRoute from "./hoc/Authenticate";

class App extends Component {
  render() {
    return (
      <div>
        <h1> This should appear on all routes </h1>
        <div>
          <h1>This should only appear on protected routes</h1>
          <Route exact path="/welcome" isAuthenticated={true} component={AuthenticateRoute(Welcome)}/>
          <Route exact path="/" isAuthenticated={true} component={AuthenticateRoute(Welcome)}/>
        </div>
        <Route exact path="/login" component={Login} />
      </div>
    );
  }
}

0 个答案:

没有答案