Angular2 users are prompted when they close the page or return to the previous page

I want to see how to close the router page or return to the previous router page after the user enters the page. A prompt box appears when the user clicks OK and then closes or returns. Can bosses do this?


Yes, subscribe to the route change, and then operate


CanDeactivate

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]
}) 

that's about it. You can see it on the official website. There are also cases
ide/router-sharpemcandeactivateem-handling-unsaved-changes" rel=" nofollow noreferrer "> https://angular.cn/guide/rout.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1beea9b-31c02.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1beea9b-31c02.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?