【问题标题】:React js component on router / header footer nav on switch路由器上的反应js组件/开关上的页眉页脚导航
【发布时间】:2019-12-11 22:50:14
【问题描述】:

您好,在我的路线文件中,我设置了 struct header 导航栏和 switch 页脚

const AppRouter = () => (
  <BrowserRouter>
          <Route path="/login" component={AuthPage} exact={true} /> 
          <Route path="/dashboard/addProduct" component={AddProduct} exact={true} /> 
   <div>
    <Header/>
    <Navigation/>
    <Container maxWidth="lg" >
      <Switch>
        <Route path="/" component={LandingPage} exact={true} /> 
        <Route path="/xd" component={AuthPage} exact={true} /> 
        <Route component={NotFoundPage} />
      </Switch>
      </Container>
    </div>  
  </BrowserRouter>
);

基本上我有一个路由器应用程序 我在哪里有我的导航栏页脚页眉和我的内容

我的内容将与开关 只渲染我的内容

它工作正常,但我有一些路线我不想呈现我的导航栏页脚标题 我怎么会得到这个??

【问题讨论】:

    标签: reactjs redux


    【解决方案1】:

    Route 中的path 属性也接受路径数组。您始终可以设置这些路径,您希望组件在哪里呈现。只需移动您的例如Header 组件到 Route 并指定您希望它出现的确切位置。

    <Route path={['/routeYouWantHeaderToRender', 'otherRoute']} component={Header} /> 
    

    【讨论】:

    • 但是这样做我仍然只能更新我的内容/主要内容?
    • 我做到了,我的标题刚刚弹出我的标题,我对如何做有点困惑使用它
    • @SpiritYang 如果你使用 Route 记得删除 &lt;Header /&gt;
    • 是的,我这样做了: 但只有我的标题渲染/我的导航没有
    • @SpiritYang 你能尝试添加exact 道具吗? &lt;Route path={['/', '/ xd']} exact component={Header} /&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多