If I have a form in a view (Angular). When user tries to navigate away from there, and I want a confirmation message to appear. How can I do that?
In My example site the user should verify secure pin while navigating to his/her Personal Details page. For all other pages user don't need secure pin. After Secure pin verification success then only he should navigate to "Personal Details" otherwise the user should be in same page.
private routerChangeListener() {
this.router.events.subscribe(event => {
if (event instanceof NavigationStart) {
this.isPersonalDetailsNavigation(event.url);
}
});
}
private verfiyIsNavigatingToMedication(url: string) {
url = url.replace('/', '');
if (url === 'personal-details') {
showPinVerficationPopup();
} else {
console.log('This Is Not Personal Details Page Navigation');
}
}
private showPinVerficationPopup() {
if(verificationSuccess) {
// This Will Navigate to Personal Details Page
this.router.navigate(['personal-details']);
} else {
// This Will Prevent Navigation
this.router.navigate([this.router.url]);
}
}