簡體   English   中英

使用后退按鈕,然后單擊routerLink會導致錯誤

[英]Using back button and then clicking routerLink results in error

在包裝了角度應用程序的cordova應用程序中,單擊“后退”按鈕后,該應用程序似乎不再位於“角度區域”中,因此,如果我此后單擊任何routerlink,則它什么也不做,並且會拋出錯誤, Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()

嘗試將“ pathMatch:'full'”添加到路由。 還嘗試了以下解決方案: Angular 7 routerLink指令警告“在Angular區域之外觸發了導航” ,它可以工作,但是我寧願不必編寫this.ngZone.run(() => this.router.navigateByUrl(''))在每一頁上。 我覺得routerLink =“”語法更加簡潔。

我單擊的按鈕如下所示:

<button type="button" class="btn btn-success  btn-wide" routerLink="/search-by-keyword">

中斷的代碼如下(請注意,所有布爾值都是真實的)

navigateByUrl(url, extras = { skipLocationChange: false }) {
        if (isDevMode() && this.isNgZoneEnabled && !NgZone.isInAngularZone()) {
            this.console.warn(`Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?`);
        }

如果我只是在Angular中運行它,則效果很好。 但是,當我運行將其包裝的cordova應用程序時,它失敗了。 因為此錯誤僅發生在DevMode中,所以我甚至還需要擔心嗎?

提前致謝。

我們遇到了相同的問題,最終在應用程序的一項服務中創建了“重定向”功能,該功能使用ngZone包裝導航,然后將所有路由傳遞到該處:

import { Injectable, NgZone } from '@angular/core';
...
constructor(
    private ngZone: NgZone,
    ...

public redirect(routerArray: any) {
    this.ngZone.run(() => {
        this.router.navigate(routerArray);
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM