My goal is to disable the back button of browser window. So, In my component, I am trying to listen for the path, for that I have imported location from angular/common and trying to subscribe it, but it does not seems to working for me. here is my code snippet of that perticular component where i want to disable back button.
import { DataService } from './../../../shared/services/data.service';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from "@angular/common";
@Component({
selector: 'app-confirmation',
templateUrl: './confirmation.component.html',
styleUrls: ['./confirmation.component.scss']
})
export class ConfirmationComponent implements OnInit {
userInput;
customWindow;
time;
message: string;
constructor(private location: Location, private dataService: DataService, private router: Router) {
this.dataService.currentMessage
.subscribe(message => (this.message = message));
console.log(this.message);
this.dataService.timeSource.subscribe(time => (this.time = time));
console.log(this.time);
}
ngOnInit(): void {
this.customWindow = window.open("", "_blank", "");
console.log('here');
console.log(this.location);
this.location.subscribe(x => console.log(x));
}
close () {
console.log(this.customWindow);
// this.customWindow.close();
console.log('666');
// this.router.navigate(['login']);
}
}