在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ angular2 用戶關閉頁面或返回上一頁面時出現(xiàn)提示

angular2 用戶關閉頁面或返回上一頁面時出現(xiàn)提示

我想在用戶進入一個router頁面后 這時用戶如何關閉網(wǎng)頁或返回上一router頁面時 出現(xiàn)一個提示框 用戶點擊確認時再關閉或返回 請問大佬們可以有這種操作嗎

回答
編輯回答
澐染

可以的,訂閱路由變化,再操作

2018年5月25日 01:12
編輯回答
萌面人
CanDeactivate
2018年8月6日 09:22
編輯回答
我以為
import { CanDeactivate } from '@angular/router';
import { ProductComponent } from '../product/product.compnent';

export class UnsavedGuard implements CanDeavtivate<ProductComponent>{
    canDeavtivate(componnet: ProductComponent){
        return window.confirm("確定要離開嗎");
    }
}

// route.module.ts
import { UnsavedGuard } from './xx/unsaved.guard';

const routes: Routes = [
    
    { path: 'product', component: ProductComponent, canDeactivate:[UnsavedGuard] }
]
@NgModule({
    provider: [UnsavedGuard]
}) 

大概就是這樣,可以在官網(wǎng)看看也有案例
https://angular.cn/guide/rout...

2017年6月8日 22:05