문제 설명
폐쇄 함수에서 경로를 점프할 때 가끔 경로를 점프할 수 없고 Navigation Triggered Outside Angular zone 메시지가 표시되는 경우가 있습니다. 'ngZone.run()' 호출을 잊으셨나요?
해결책
import { Component, OnInit, NgZone } from '@angular/core';
export class * {
constructor(
private route: Router,
private ngZone: NgZone
) {}
public navigate(commands: any[]): void {
this.ngZone.run(() => this.route.navigate(commands)).then();
}
}
클로저 함수를 호출하기 전에 that = this를 선언하고 that.navigate([*])를 사용하세요.