content: Example shows uncommon IonRouterOutlet usage

Đang mở Phù hợp với người mới
#3,583 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
angular, typescript
Lĩnh vực
documentation, mobile-dev

Hướng nghiên cứu

Mở tài liệu được liên kết về nút quay lại phần cứng và kiểm tra tab Angular (Standalone), tập trung vào cách IonRouterOutlet được inject. Cập nhật ví dụ để hiển thị một cách tiếp cận hoạt động được với component cấp cao nhất cho hành vi thoát mặc định theo kiểu Android, sau đó xác minh rằng đoạn mã được hiển thị khớp với trường hợp sử dụng đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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();
    }
  });
}
Ngôn ngữ chính
MDX
Star
621
Fork
3.2k
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
86

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ionic-team/ionic-docs

Tất cả issue của ionic-team/ionic-docs

Issue tương tự

Thêm issue về Documentation

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.