content: Example shows uncommon IonRouterOutlet usage

Open Beginner friendly
#3,583 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
angular, typescript

Research direction

Open the linked hardware back-button documentation and inspect the Angular (Standalone) tab, focusing on how IonRouterOutlet is injected. Update the example to show a working top-level component approach for the default Android-style exit behavior, then verify the displayed code matches that use case.

Written by the indexing model from the issue text.

Description

content package: angular
URL

https://ionicframework.com/docs/developing/hardware-back-button#exiting-the-app

Issue Description

On the linked page (I am referencing the Angular (Standalone) tab), the IonRouterOutlet is injected via the constructor.
However, this only works if it used in a subcomponent of the app and not in AppComponent and, I would argue that this is a rather uncommon use-case, as the usual developer probably only wants to add it to the top-most component.

In my case, I had to search for quite some time to find a really neat solution in the following issue comment, and according to the reactions I am not alone (note that the issue is also locked since nearly 4 years!):
https://github.com/ionic-team/ionic-framework/issues/21630#issuecomment-683007162

IMO, the docs example should show a working way of implementing the default behavior (like in native Android apps) in a straightforward way like:

import { ViewChild } from '@angular/core';
import { IonRouterOutlet, Platform } from '@ionic/angular/standalone';
import { App } from "@capacitor/app";

// ...

@ViewChild(IonRouterOutlet, {static: true}) routerOutlet?: IonRouterOutlet

constructor(private platform: Platform) {
  this.platform.backButton.subscribeWithPriority(-1, () => {
    if (this.routerOutlet && !this.routerOutlet.canGoBack()) {
      App.exitApp();
    }
  });
}
Dominant language
MDX
Stars
621
Forks
3.2k
Avg merge
1d 2h
Merged PRs (30d)
86

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ionic-team/ionic-docs

All issues in ionic-team/ionic-docs

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.