简体   繁体   English

离子4(角形) <ion-router-outlet> 不能正常工作

[英]Ionic 4 (Angular) <ion-router-outlet> doesn't work properly

I am trying to make ionic 4 routing work , This is my home component: 我正在尝试使ionic 4路由工作,这是我的家庭组件:

<ion-header>
  <ion-toolbar color="primary" class="animated fadeIn">
    <ion-buttons slot="start">
      <ion-menu-button color="secondary"></ion-menu-button>
      <ion-back-button>Back</ion-back-button>
    </ion-buttons>
  </ion-toolbar>
</ion-header>

<ion-content padding class="animated fadeIn login auth-page">
  <ion-router-outlet main></ion-router-outlet>
</ion-content>

Those are navbars html file: 这些是导航栏html文件:

<ion-menu-toggle auto-hide="false" *ngFor="let p of driverNavBarComponents">
    <ion-item [routerDirection]="p.direction" [routerLink]="[p.url]" color="primary">
      <ion-icon slot="start" [name]="p.icon"></ion-icon>
      <ion-label>
        {{p.title}}
      </ion-label>
    </ion-item>
</ion-menu-toggle>

and this is the driverNavBarComponent inside ts file: 这是ts文件中的driverNavBarComponent:

public driverNavBarComponents = [
    {
      title: 'Home',
      url: '/driver/cabinet',
      icon:'home',
      direction:'root',
    },
    {
      title: 'Profile',
      url: '/driver/cabinet/profile',
      icon:'contact',
      direction:'forward',
    }
  ]; 

When I go from /driver/cabinet to /driver/cabinet/profile no back button is shown. 当我从/driver/cabinet转到/driver/cabinet/profile没有显示后退按钮。 Also when I return to home from navbar, route changes in url, but I still see profile page. 另外,当我从导航栏返回家中时,URL中的路由发生了变化,但是我仍然看到配置文件页面。 so what am I doing wrong? 那我在做什么错呢?

That's how my router module looks like: 这就是我的路由器模块的样子:

RouterModule.forChild([
      { 
        path: 'driver/cabinet', 
        component: DriverHomeComponent ,
        children:[
          {
            path: 'profile',
            component: DriverProfileComponent
          },
          {
            path: 'tracking',
            component: DriverTrackingComponent
          }
        ]
      }
    ]),

ion-router-outlet does not belong in the ion-content. ion-router-outlet不属于离子含量。

It's a top level component that is not supposed to be a child element. 它是顶级组件,不应被视为子元素。

Please see the starter projects. 请参阅入门项目。

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

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