question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

【ionic 4】ionic back button issue

See original GitHub issue

i create a tabs which include three pages

tabs ----home ----menu ----contact

in home page i add a detail page

when click button on home page, can be push to detail page


import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss']
})
export class HomePage {
  constructor(private router: Router) { 

  }
  pushTo(id){
    this.router.navigate(['/detail/'+id]);
  }
}

so when i click button on home page, it will go detail page, and then i click back button it go back to home page, everything looking good.

problem is if i click button again, detail page button is missing and have no page transition

on console there show “router-outlet destroyed”

here is my routing module

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

const routes: Routes = [
  { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'detail/:id', loadChildren: './detail/detail.module#DetailPageModule' }
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}

here is my tabs routing module

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

import { TabsPage } from './tabs.page';
import { HomePage } from '../home/home.page';
import { AboutPage } from '../about/about.page';
import { ContactPage } from '../contact/contact.page';

const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      {
        path: 'home',
        outlet: 'home',
        component: HomePage
      },
      {
        path: 'about',
        outlet: 'about',
        component: AboutPage
      },
      {
        path: 'contact',
        outlet: 'contact',
        component: ContactPage
      }
    ]
  },
  {
    path: '',
    redirectTo: '/tabs/(home:home)',
    pathMatch: 'full'
  }
];

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

here is detail.page.html

<ion-header>
  <ion-toolbar>
    <ion-buttons slot="start">
      <ion-back-button></ion-back-button>
    </ion-buttons>
    <ion-title>详情</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content padding>
{{post_data}}
</ion-content>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:21
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
gulullucommented, Nov 21, 2018

The issue was fixed in last ionic 4 version 😄

‘router-outlet destroyed’ issue still existing on ‘4.0.0-beta.16’.

2reactions
paulstelzercommented, Dec 8, 2018

Thanks for the issue! As @arihantdaga mentioned this should work in beta.17, so I close this here. If the issue occurs again, please open a new issue and describe what’s not working correct

UPDATE: The main issue was because of tabs. It’s correct that tabs are not working correctly with the back button, but with the next betas, we will have a refactor of the tabs (see #16619). So i close this here and please follow that issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic 4 back button not working
Ionic 4 back button not working · Go to any page · Press the hardware back button · Doesn't go back.
Read more >
IONIC back button not working at any case - Stack Overflow
If I navigate from home page to login page the back button should work which is not working. even if I add defaultHref...
Read more >
Ionic: How to Simulate Android back button in Browser
The general idea is to test the behavior of Android back button on the second page. We can start creating our app by...
Read more >
Ionic hardware back button event: How to override it
In this Ionic 5/4 + Capacitor tutorial. We'll go through how to override the hardware back press event. Which shows a confirm alert...
Read more >
Ionic Hardware Back & Browser Back - YouTube
The default behaviour for the Ionic back button or hardware back on Android is not alway 100% what you need, so today we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found