0
當在支付網關後重定向URL,要禁用角2.I後退按鈕後退按鈕嘗試使用窗口事件beforeunload和onPopstate,他們都不似乎工作禁用angular2
我也試圖使用window.history.forward但不起作用 。請建議!
當在支付網關後重定向URL,要禁用角2.I後退按鈕後退按鈕嘗試使用窗口事件beforeunload和onPopstate,他們都不似乎工作禁用angular2
我也試圖使用window.history.forward但不起作用 。請建議!
您可以使用角度2中的AuthGuard來滿足您的要求。你只需要實現CanActivate,寫你的業務邏輯
import { Injectable } from '@angular/core';
import { Router, CanActivate, CanDeactivate } from '@angular/router';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router) { }
canActivate() {
if (localStorage.getItem('payment')) { //key to indicate that user has visited payment gateway (you can change as per your needs)
return false;
}
return true;
}
}
路由
{
path: 'home',
component: homeComponent,
canActivate: [AuthGuard]
}
希望它可以幫助!
您無法禁用瀏覽器的後退按鈕。相反,你應該向用戶顯示一條消息,他們不應該按回按鈕。 – Dhyey
如果事件被捕獲,也可以添加消息,這些事件不會在我的頁面上被捕獲,這是付款後的重定向頁面。它適用於其他頁面,但只有當我在歷史記錄中添加一些網址時 – Gurpreet
這是我爲第一頁完成的工作主機:
{ '(window:popstate)': 'onWindowScroll($event)' },history.pushState(null, null, window.location.pathname); onWindowScroll(event: Event): void { if (confirm("You have already checked out, do you still want to exit")) { history.go(-1); } else { history.pushState(null, null, window.location.pathname); } }
但是,付款後這不適用於重定向頁面 – Gurpreet