Skip to content

[Ionic v4] Multiple ion-router-outlets not working #15370

Closed

Description

Bug Report

Ionic Info

Ionic:
   ionic (Ionic CLI)          : 4.1.1 (C:\Users\knuterik\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.12
   @angular-devkit/core       : 0.7.3
   @angular-devkit/schematics : 0.7.3
   @angular/cli               : 6.1.3
   @ionic/ng-toolkit          : 1.0.6
   @ionic/schematics-angular  : 1.0.5

System:

   NodeJS : v9.3.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.0
   OS     : Windows 10

Describe the Bug
Navigation is stuck after navigating between two components with child routes and ion-router-outlets. This works in angular with router-outlet but not after IonicModule is imported.

Steps to Reproduce
Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/github/knutto/bug-ion-router-outlet
  2. Click through Tab 1 - 3 and see the content change.
  3. Click "Second Tabs Page"
  4. Click through Tab 4 - 6 and see the content change.
  5. Click "First Tabs Page" (navigating you back)
  6. The content is now stuck to the last tab you clicked.

Related Code
https://stackblitz.com/github/knutto/bug-ion-router-outlet

https://github.com/knutto/bug-ion-router-outlet

Expected Behavior
Navigation should still work after navigating from /first to /second

The docs states that ion-router-outlet should behave as angular's router-outlet but it does not support having multiple/nested ion-router-outlet

Update
This was supposedly fixed in f84bb76 (beta.3) and closed #14888

After this update only the first tabs/ion-router-outlet page is stuck - the second is functioning as intended.

Activity

  1. abennouna commented on Aug 29, 2018

    @abennouna
    Contributor

    Your Ionic Info says "@ionic/angular 4.0.0-beta.0" have you tried with the updated beta?

  2. naveedahmed1 commented on Aug 30, 2018

    @naveedahmed1

    Same issue here, another thing while we are on a route in child router outlet and use this.routerOutlet.pop(); to go back and then want to visit same child component 2nd time this doesn't work.

  3. jurgen-reconcept commented on Sep 5, 2018

    @jurgen-reconcept

    I'm encountering the same issue on beta.7.

    • It doesn't matter if I'm lazy loading the page or not
    • I've also tried to wrap the tab pages in an extra ion-router-outlet, but the problem persists.
    • I've tried removing all other outlets from the ion-tabs and removing all references to the outlet name, but this doesn't solve the problem either.
    • When I remove my tabs and just use a (nested) ion-router-outlet, the problem persists. I.e. the problem is not with the tabs per se.

    Hope this helps!

    Update:

    I started with the blank starter and added a second page 'Test'. If I navigate from Home to Test, it works with a nice animation. If I navigate back from Test to Home, it works with the proper reverse animation. When I try to navigate from there to Test again, nothing happens. So in conclusion: this doesn't seem to have anything to do with tabs or nested router outlets, but seems to be a core problem. See below for my package info:

    {
      "name": "testionic",
      "version": "0.0.1",
      "author": "Ionic Framework",
      "homepage": "http://ionicframework.com/",
      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
      },
      "private": true,
      "dependencies": {
        "@angular/common": "~6.1.1",
        "@angular/core": "~6.1.1",
        "@angular/forms": "~6.1.1",
        "@angular/http": "~6.1.1",
        "@angular/platform-browser": "~6.1.1",
        "@angular/platform-browser-dynamic": "~6.1.1",
        "@angular/router": "~6.1.1",
        "@ionic-native/core": "5.0.0-beta.15",
        "@ionic-native/splash-screen": "5.0.0-beta.15",
        "@ionic-native/status-bar": "5.0.0-beta.15",
        "@ionic/angular": "4.0.0-beta.7",
        "core-js": "^2.5.3",
        "rxjs": "6.2.2",
        "zone.js": "^0.8.26"
      },
      "devDependencies": {
        "@angular/cli": "~6.1.1",
        "@angular/compiler": "~6.1.1",
        "@angular/compiler-cli": "~6.1.1",
        "@angular/language-service": "~6.1.1",
        "@angular-devkit/architect": "~0.7.2",
        "@angular-devkit/build-angular": "~0.7.2",
        "@angular-devkit/core": "~0.7.2",
        "@angular-devkit/schematics": "~0.7.2",
        "@ionic/ng-toolkit": "^1.0.0",
        "@ionic/schematics-angular": "^1.0.0",
        "@types/jasmine": "~2.8.6",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "~10.9.2",
        "codelyzer": "~4.4.2",
        "jasmine-core": "~2.99.1",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~3.0.0",
        "karma-chrome-launcher": "~2.2.0",
        "karma-coverage-istanbul-reporter": "~2.0.0",
        "karma-jasmine": "~1.1.1",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.4.0",
        "ts-node": "~7.0.0",
        "tslint": "~5.11.0",
        "typescript": "~2.9.2"
      },
      "description": "An Ionic project"
    }
    
  4. jurgen-reconcept commented on Sep 5, 2018

    @jurgen-reconcept

    These issues seem to be the same:

    There are also some open issues about a nav back button bug, may also be the same.

  5. mhartington commented on Sep 12, 2018

    @mhartington
    Contributor

    Closing as duplicate of #14566

    Please track that issue instead of opening new issues.

  6. jurgen-reconcept commented on Sep 13, 2018

    @jurgen-reconcept

    @mhartington I don't think it's a duplicate. Like I said in my comment above the problem is not with Tabs per se, and after a little more digging I find it's still a problem when I don't lazy load anything.

  7. joostvandoremalen commented on Sep 13, 2018

    @joostvandoremalen

    @jurgen-reconcept @mhartington Might it be due to relative routing as reported here: #15449 ?

  8. mhartington commented on Sep 13, 2018

    @mhartington
    Contributor

    Seems like a few things, but mostly coming down to needing to specify a name for the multiple router-outlets. other wise, there's no logic in place to say what outlet should be active.

    https://github.com/mhartington/bug-ion-router-outlet

    This has the fixed setup. Let me know if that solves your issues @jurgen-reconcept

  9. jurgen-reconcept commented on Sep 13, 2018

    @jurgen-reconcept

    @doender i can confirm that uses absolute paths fixes it for me, but it's definitely less than ideal.

    @mhartington your repo seems empty

  10. mhartington commented on Sep 13, 2018

    @mhartington
    Contributor

    😄 Silly me, forgot to push. Refresh

  11. 25 remaining items

  12. idanzapp commented on Oct 8, 2018

    @idanzapp

    i found a temporal hacky workaround till they fix it, since named outlets breaks lazy load, and the no-named outlets breaks with components with childs, doing a 'copy' of the directive , will make that the views can difference between 1 outlet and the other one,

    i got a full lazy loaded app with 3 levels of tabs finally working without any problem.

    • The tabs component just use ion-toolbar and ion-buttons, to make the tabs (now im going to try,if it works with the standard ion-tabs component )

    • bn8-router-outlet is a copy of the ion-router-outlet directive (in my case i removed, the navCrtl and stack stuff, since im not going to use it)

    • navigator.html =>

    <ion-content padding>
      <bn8-router-outlet></bn8-router-outlet>
    </ion-content>
    <ion-footer>
      <tabs [tabs]=mainTabs></tabs>
    </ion-footer>
    
    • navigator-routing.module.ts =>
    const routes: Routes = [{
      path:'',
      component: NavigatorPage,
      children: [
        { path: '', redirectTo: 'eventos-handler', pathMatch: 'full' },
        { path: 'eventos-handler', loadChildren: './event-handler/event-handler.module#EventHandlerPageModule' },
        { path: 'entradas', loadChildren: './entradas/entradas.module#EntradasPageModule' },
        { path: 'chat', loadChildren: './chat/chat.module#ChatPageModule' },
        { path: 'notificaciones', loadChildren: './notificaciones/notificaciones.module#NotificacionesPageModule'  },
        { path: 'perfil', loadChildren: './perfil-handler/perfil-handler.module#PerfilHandlerPageModule' },
        { path: '**', redirectTo: '', pathMatch: 'full' }    
      ]
    },
    { path: '**', redirectTo: '', pathMatch: 'full' },
    ]
    
    • event-handle.html (child of navigator) =>
    <tabs [tabs]=eventosTabs></tabs>
    <ion-content>
     <ion-router-outlet></ion-router-outlet>
    </ion-content>
    
    • event-handler-routing.module.ts =>
    const routes: Routes = [
      {
        path: '',
        component: EventHandlerPage,
        children: [
          {
            path: '',
            children: [
              { path: '', redirectTo: 'eventos', pathMatch: 'full'  },
              { path: 'eventos', loadChildren: './eventos/eventos.page.module#EventosPageModule' },
              { path: 'planes', loadChildren: './planes/planes.page.module#PlanesPageModule' },
              { path: 'clubs', loadChildren: './clubs/clubs.page.module#ClubsPageModule' },          
              { path: 'mapa', loadChildren: './mapa/mapa.page.module#MapaPageModule' },          
              { path: '**', redirectTo: 'eventos', pathMatch: 'full' }
    
            ]
          }
        ]
      },
      { path: '**', redirectTo: '', pathMatch: 'full' }
    ]
    

    Ps. Probably just using "<router-outlet>" instead the 'new directive', will do the trick aswell

  13. giacomocerquone commented on Oct 12, 2018

    @giacomocerquone

    @idanzapp well it doesn't work for me. I tried to clone the directive (plus idk why it's a directive if it's used as a component) and i also imported all the stuff ('cause i needed stack etc.) but it errors with a TypeError: containerEl.commit

  14. idanzapp commented on Oct 13, 2018

    @idanzapp

    try to use <router-outlet> in the 1st level instead the copied directive, and <ion-router-outlet> in the nested ones

  15. giacomocerquone commented on Oct 15, 2018

    @giacomocerquone

    @idanzapp actually I refactored my application in order to not use multiple nested ion-router-outlet and... the same problem occurs... now I don't even have anymore "router-outlet destroyed" logged in the console... this is weird as f***.

    I'm going to create a well documented issue with an example video on this repo that groups all the outlet related issues too like this.

  16. RHinderiks commented on Nov 13, 2018

    @RHinderiks

    Do named router outlets as of angular 7 support lazy loading ? Or is this something that needs to be fixed by ionic ?

  17. manucorporat commented on Dec 8, 2018

    @manucorporat
    Contributor

    Will be fixed by #16637

  18. giacomocerquone commented on Dec 8, 2018

    @giacomocerquone

    @manucorporat sorry to bother, but part of this issue is involved in this other issue #15959
    Means that the other one is solved too?

  19. ionitron-bot commented on Jan 7, 2019

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  20. locked and limited conversation to collaborators on Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

package: angular

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions