6

我正在构建 Ionic React 应用程序,离子的版本是 5。在我的应用程序中,我有底部导航。我在 App.tsx 中提到过底部导航的逻辑。

我在仪表板页面上有一个添加按钮,单击该按钮我希望打开一个不包含底部导航的页面。我在互联网上得到了很多针对 Ionic-Angular 的答案。我正在专门寻找 Ionic-React 的答案。

App.tsx    
     <IonContent>
        <IonReactRouter>
          <IonTabs>
            <IonRouterOutlet>
              <Route path="/profile" component={Profile} exact={true} />
              <Route path="/dashboard" component={Dashboard} exact={true} />
              <Route path="/dashboard/addInfo" component={Info} exact={true} />
              <Route path="/" render={() => <Redirect to="/dashboard" />} exact={true} />
            </IonRouterOutlet>
            <IonTabBar slot="bottom">
              <IonTabButton tab="home" href="/home">
                <IonIcon icon={home} />
                <IonLabel>Home</IonLabel>
              </IonTabButton>
              <IonTabButton tab="profile" href="/profile">
                <IonIcon icon={profile} />
                <IonLabel>Profile</IonLabel>
              </IonTabButton>
              <IonTabButton tab="dashboard" href="/dashboard">
                <IonIcon icon={grid} />
                <IonLabel>Dashboard</IonLabel>
              </IonTabButton>
            </IonTabBar>
          </IonTabs>
        </IonReactRouter>
      </IonContent>
4

2 回答 2

2

这可能是@MostafaHarb 试图解释的。你可以有嵌套的 IonRouterOutlets,所以将你的选项卡放在一个 TabContainer 组件中,离开你的主 App.tsx(这里显示为/tabsRoute 上的渲染道具)。您可能需要提供一个后备路由,在这种情况下,tabs当路径为"/"

        <IonReactRouter>
              <IonRouterOutlet>
                <Route path="/notabs" render={() => <div>a page no tabs</div>} />
                <Route
                  path="/tabs"
                  render={() => (
                      <IonTabs>
                        <IonRouterOutlet>
                          <Route
                            path="/tabs/tab1"
                            component={Tab1}
                            exact={true}
                          />
                          <Route
                            path="/tabs/tab2"
                            component={Tab2}
                            exact={true}
                          />
                          <Route
                            path="/tabs/tab3"
                            component={Tab3}
                            exact={true}
                          />
                        </IonRouterOutlet>
                        <IonTabBar slot="bottom">
                          <IonTabButton tab="tab 1" href="/tabs/tab1">
                            <IonIcon icon={circle} />
                            <IonLabel>Tab1</IonLabel>
                          </IonTabButton>
                          <IonTabButton tab="tab 2" href="/tabs/tab2">
                            <IonIcon icon={square} />
                            <IonLabel>Tab2</IonLabel>
                          </IonTabButton>
                          <IonTabButton tab="tab 3" href="/tabs/tab3">
                            <IonIcon icon={triangle} />
                            <IonLabel>Tab3</IonLabel>
                          </IonTabButton>
                        </IonTabBar>
                      </IonTabs>
                  )}
                />
                <Route
                  path="/"
                  render={() => <Redirect to="/tabs" />}
                  exact={true}
                />
              </IonRouterOutlet>
        </IonReactRouter>
    </IonApp>
  );

祝你好运!

于 2020-08-26T19:49:48.723 回答
1

我做了这样的事情,这对我有用。我为选项卡创建了一个 ID,然后对其进行操作以显示或隐藏

    function showTab() {
       const tabBar = document.getElementById('appTabBar');
       if (tabBar !== null) {
           console.log("enabled")
           tabBar.style.display = 'flex';
       }
    }

function hideTab() {
   const tabBar = document.getElementById('appTabBar');
   if (tabBar !== null) {
      tabBar.style.display = 'none';
   }
}

<IonTabBar slot="bottom" id="appTabBar" >
      <IonTabButton tab="account" href="/account">
           <IonIcon icon={personCircleOutline}/>
           <IonLabel>Profile</IonLabel>
           </IonTabButton>
    </IonTabBar>
于 2020-05-30T03:41:19.663 回答