简体   繁体   English

带有侧面菜单的Ionic 4应用程序会更新URL,但不会更新视图

[英]Ionic 4 app with side menu updates URL but not the view

My project consists of an Ionic 4 app with a side menu and double routing where the default routes: Routes is for login and menu, and the other is in menu folder. 我的项目由一个带有侧面菜单和双重路由的Ionic 4应用组成,其中默认路由:路由用于登录和菜单,另一个在菜单文件夹中。

The problem is that when I open the burger menu and click on any item in it changes the URL, but does not load the view. 问题是,当我打开汉堡菜单并单击其中的任何项目时,URL都会更改,但不会加载视图。 Nevertheless, when I refresh the browser page, then loads it. 不过,当我刷新浏览器页面时,然后加载它。

So, I tried this out on a test page: 因此,我在测试页上进行了尝试:

a.page.ts 页面

ngOnInit() { console.log("onInit"); }
ionViewWillEnter() { console.log("will enter"); }
ionViewDidEnter() { console.log("did enter"); }
ionViewWillLeave() { console.log("will leave"); }
ionViewDidLeave() { console.log("did leave"); }
ngOnDestroy() { console.log("on destroy"); }

And prints onInit , will enter and did enter on console, but as said before the view does not show. 并打印onInit在控制台上输入确实输入 ,但是如前所述,该视图未显示。

What the hell is happening here or how can I make the app load the pages normally without having to force refreshing (not programmatically, but with F5 button) the browser, please? 请问这是怎么回事,或者我该如何使应用正常加载页面,而不必强制刷新(不是通过编程方式,而是使用F5按钮)浏览器?

For more information I'll add all below. 有关更多信息,我将在下面添加所有内容。

The menu has been generated as a page and has this structure: 菜单已作为页面生成,并具有以下结构:

menu.page.html menu.page.html

<ion-menu contentId="mainMenu" side="start" type="overlay">
  <ion-header>
    <ion-toolbar>
      <ion-title>Menu</ion-title>
    </ion-toolbar>
  </ion-header>
  <ion-content>
    <ion-list>
      <ion-menu-toggle auto-hide="true" *ngFor="let route of routes">
        <!-- Uncomment any line below. The behavior is the same. -->
        <!-- <ion-item [routerLink]="route.url"> -->
        <!-- <ion-item (click)="goToPage(route.url)"> -->
          <ion-label>{{route.title}}</ion-label>
        </ion-item>
      </ion-menu-toggle>
    </ion-list>
  </ion-content>
</ion-menu>

<ion-router-outlet id="mainMenu" main><ion-router-outlet>

menu.module.ts menu.module.ts

[...]

const routes: Routes = [
  {
    path: '',
    component: MenuPage,
    children: [
      { path: 'home', loadChildren: '../home/home.module#HomePageModule' },
      { path: 'a', loadChildren: '../a/a.module#APageModule' }
    ]
  }
];

[...]

menu.page.ts menu.page.ts

[...]

public readonly routes = [
  { title: 'home', url: '/menu/home' },
  { title: 'A', url: '/menu/a' }
];

public goToPage(url: string): void { this.router.navigateByUrl(url); }

[...]

Ionic details: 离子详细信息:

"@ionic/angular": "^4.6.0"
"@angular/router": "^7.2.2"
Ionic cli: 5.2.1

菜单组件位于路径'' ,子模块APageModule位于路径a ,因此总路径将为/a而不是/menu/a

Okay. 好的。 So, as commented Joel Joseph here , the problem is that the <ion-router-outlet> tag at menu.page.html is not closed. 因此,正如Joel Joseph 在这里评论的那样,问题在于menu.page.html上的<ion-router-outlet>标记未关闭。 The rest of the code is okay. 其余的代码都可以。

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

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