繁体   English   中英

每个页面的自定义大屏幕

[英]Custom Jumbotron for each page

我正在尝试使我的 Jumbotron 特定于页面。 所以我在我的 App.js 中创建了用户类型数组,同时我在这个页面上发送类型作为道具:

const userTypes = {
    individual: [
      {
        _id: '1',
        name: 'Individual',
        quote: 'Download the app to track your code',
      },
    ],
    broker: [
      {
        _id: '2',
        name: 'Broker',
        quote: 'Download the app to see all the drivers',
      },
    ],
    dealer: [
      {
        _id: '3',
        name: 'Dealer',
        quote: 'Download the app to do something else',
      }
    ],
  };
<Route exact path="/" component={Home} id={userTypes.individual._id} type={userTypes.individual.type} quote={userTypes.individual.quote}/>
          <Route exact path="/brokers" component={Broker} id={userTypes.broker._id} type={userTypes.broker.type} quote={userTypes.broker.quote}/>
          <Route exact path="/dealers" component={Dealer} id={userTypes.dealer._id} type={userTypes.dealer.type} quote={userTypes.dealer.quote}/>

所以我想要做的是在主页、经纪人和经销商页面上显示报价属性。 例如,在主页中,我将属性作为道具发送,所以这是我的主页:

function Home(props) {  
  const history = useHistory();  
    return (
  <Styles>
    <JumbotronClassic history={history} props={props}/>
      
  </Styles>
);
}

export default Home;

所以根据这里的道具,我期待在 Jumbotron 中看到引用,因为这是我的 Jumbotron:

const JumbotronClassic = (props) => {
  return (
    <div>
      <Jumbotron fluid>
        <Container fluid>
          <Row>
            <Col>{props.quote}</Col>
            <Col>
              <InstantQuote />
            </Col>
          </Row>
        </Container>
      </Jumbotron>
    </div>
  );
};

但不幸的是,我没有看到我期望的任何东西。 所以我猜我在发送道具时做错了什么。 你能检查一下并让我知道我做错了什么吗?

那是因为idtypequote被传递给了Route组件,而不是你的component prop 中指定的component 如果您的Route组件是react-router-dom组件,请改用render prop。

例如

<Route
  exact
  path="/"
  render={props => <Home {...props} id={userTypes.individual._id} type={userTypes.individual.type} quote={userTypes.individual.quote} />}
/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM