【问题标题】:How to create route like ( domain.com / dashboard/products ) In React JS如何在 React JS 中创建类似 (domain.com/dashboard/products) 的路由
【发布时间】:2019-03-02 15:40:31
【问题描述】:

我是 ReactJS 的新手。我想制作可能喜欢 (dashboard/product) 的路线。怎么可能。我创建但它不能正常工作.. 可以请一些帮助我。 谢谢。

<div style={wrapperStyle.MainWrapper}>
      <h1>Dashboard Page</h1>

      <div style={wrapperStyle.leftSideMenues}>
          <h1>Left Side Menues</h1>
          <div>

          </div>
      </div>
      <Router>
              <Switch>
                  <Route path='/' exact component= {Dashboard}/>
                  <Route path='/dashboard/:organizationContact' component={OraganizationContacts}/>
                  <Route path='/dashboard/products' component={Products}/>
                  <Route path='/sales' component={Sales}/>
                  <Route path='/purchase_orders' component={PurchaseOrders}/>
                  <Route path='/shipment' component={Shipments}/>
                  <Route path='/everything' component={Everything}/>
                  <Route path='/reports' component={Reports}/>
                  <Route path='/settings' component={Settings}/>
                  <Route path='/logout' component={LogOut}/>
                  <Route component={NotFound}/>
              </Switch>
          </Router>
  </div>

【问题讨论】:

标签: javascript reactjs ecmascript-6


【解决方案1】:

您可以按以下方式重新排序路线:

<Route exact path='/dashboard/products' component={Products}/>
<Route exact path='/dashboard/:organizationContact' component={OraganizationContacts}/>

【讨论】:

  • 你的意思是我应该在所有路由中添加exact
  • Yes in react-router4 路由使用正则表达式匹配,因此通过添加 exact 它匹配确切的路由。
  • 例如在 Route 中。如果用户单击 dashboard/user 我只想显示 User Component Data 。现在它显示两个组件数据。如何避免仪表盘组件数据?
  • 如果路由是dashboard/user,按照路由应该去OraganizationContacts组件
猜你喜欢
  • 2023-02-08
  • 1970-01-01
  • 2016-11-23
  • 2020-10-25
  • 2021-10-04
  • 1970-01-01
  • 2022-08-17
  • 1970-01-01
  • 2015-12-07
相关资源
最近更新 更多