Ionic 4侧面菜单路由不会在其自己的页面上加载

时间:2019-05-03 07:45:11

标签: angular typescript ionic-framework ionic4

我在项目的辅助菜单中添加了一个新菜单。我将其与服务连接。但是,当我单击菜单时,它不会加载页面。并没有给我一个错误。我不明白为什么会这样。

如果您愿意,我可以在这里编写服务和页面模块。

我添加了一些项目代码。请帮助我。

我的app.component.ts

Acr.UserDialogs.UserDialogs.Instance.Toast(Message, new TimeSpan(3));

我的app-routing.module.ts

@Autowired
private ApplicationContext ctx;

public void processAnnotation() {
    // Getting annotated beans with names
    Map<String, Object> allBeansWithNames = ctx.getBeansWithAnnotation(TestDetails.class);
    //If you want the annotated data
    allBeansWithNames.forEach((beanName, bean) -> {
        TestDetails testDetails = (TestDetails) ctx.findAnnotationOnBean(beanName, TestDetails.class);
        LOGGER.info("testDetails: {}", testDetails);
    });
}

我的app-.module.ts

export class AppComponent {
  public appPages = [
    {
      title: 'Home',
      url: '/home',
      icon: 'home'
    },
    {
      title: 'List',
      url: '/list',
      icon: 'list'
    },
    {
      title: 'Users',
      url: '/user',
      icon: 'person'
    }

  ];
constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

我的侧面菜单代码:

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  {
    path: '',
    redirectTo: 'home',
    pathMatch: 'full'
  },
  {
    path: 'home',
    loadChildren: './home/home.module#HomePageModule'
  },
  {
    path: 'list',
    loadChildren: './list/list.module#ListPageModule'
  },
  { path: 'detail/:id', loadChildren: './detail/detail.module#DetailPageModule' },
  { path: 'user', loadChildren: './user/user.module#UserPageModule' }
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes)
  ],
  exports: [RouterModule]
})
export class AppRoutingModule {}

1 个答案:

答案 0 :(得分:0)

使用时

<ion-item [routerDirection]="'root'" [routerLink]="[p.url]">

并单击它,URL将作为参数传递::/ home

在您的情况下,因为您要从列表中获取

<ion-item [routerDirection]="'root'" routerLink="{{p.url}}">

<ion-item [routerDirection]="'root'" [routerLink]="p.url">