Disable back-page button in browser
I create auth app with routing in angular 2 with typescript. And now my task is disabled back button in browser from form localhost/form1
to localhost/login
; how implement this?
angular angular2-routing
add a comment |
I create auth app with routing in angular 2 with typescript. And now my task is disabled back button in browser from form localhost/form1
to localhost/login
; how implement this?
angular angular2-routing
add a comment |
I create auth app with routing in angular 2 with typescript. And now my task is disabled back button in browser from form localhost/form1
to localhost/login
; how implement this?
angular angular2-routing
I create auth app with routing in angular 2 with typescript. And now my task is disabled back button in browser from form localhost/form1
to localhost/login
; how implement this?
angular angular2-routing
angular angular2-routing
asked Dec 8 '16 at 9:14
eduard eduard
4228
4228
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can't really block the back button since it's a browser behavior. What you can do instead is to create a guard to handle every request, and if the request is done to load /login and the user is already loggued, simply redirect to the previous page.
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
add a comment |
I solved this in my angular cordova app to prevent app from exiting as following. Contrary to most comments I've found I had to use the "document" object instead of the "window" object to capture the backbutton event
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
Usage in a component
import { Component, HostListener } from '@angular/core';
export class myComponent {
constructor() {}
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
}
add a comment |
step 1: Import Locatoion from angular commmon
import {Location} from "@angular/common";
step 2: Initialise in constructor
private commonService: CommonService
step 3: Add function in ngOnInit of the respective coponent,
this.location.subscribe(currentLocation => {
if (currentLocation.url === '*/basic-info*') {
window.onpopstate = function (event) {
history.go(1);
}
}
});
Note: Here /basic-info will be replaced by your path.
If first time it is not working, try adding outside subscribe,
let currentUrl = window.location.href;
let tmpVar = currentUrl.includes('/basic-info');
if (currentUrl.includes('/basic-info')) {
window.onpopstate = function (event) {
history.go(1);
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41035672%2fdisable-back-page-button-in-browser%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't really block the back button since it's a browser behavior. What you can do instead is to create a guard to handle every request, and if the request is done to load /login and the user is already loggued, simply redirect to the previous page.
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
add a comment |
You can't really block the back button since it's a browser behavior. What you can do instead is to create a guard to handle every request, and if the request is done to load /login and the user is already loggued, simply redirect to the previous page.
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
add a comment |
You can't really block the back button since it's a browser behavior. What you can do instead is to create a guard to handle every request, and if the request is done to load /login and the user is already loggued, simply redirect to the previous page.
You can't really block the back button since it's a browser behavior. What you can do instead is to create a guard to handle every request, and if the request is done to load /login and the user is already loggued, simply redirect to the previous page.
answered Dec 8 '16 at 9:18
SakutoSakuto
3,48512542
3,48512542
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
add a comment |
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
Thanks for quick answer, i add something that you tell, i mean AuthGuard. But not for back page. Thanks for response.
– eduard
Dec 8 '16 at 9:46
add a comment |
I solved this in my angular cordova app to prevent app from exiting as following. Contrary to most comments I've found I had to use the "document" object instead of the "window" object to capture the backbutton event
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
Usage in a component
import { Component, HostListener } from '@angular/core';
export class myComponent {
constructor() {}
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
}
add a comment |
I solved this in my angular cordova app to prevent app from exiting as following. Contrary to most comments I've found I had to use the "document" object instead of the "window" object to capture the backbutton event
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
Usage in a component
import { Component, HostListener } from '@angular/core';
export class myComponent {
constructor() {}
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
}
add a comment |
I solved this in my angular cordova app to prevent app from exiting as following. Contrary to most comments I've found I had to use the "document" object instead of the "window" object to capture the backbutton event
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
Usage in a component
import { Component, HostListener } from '@angular/core';
export class myComponent {
constructor() {}
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
}
I solved this in my angular cordova app to prevent app from exiting as following. Contrary to most comments I've found I had to use the "document" object instead of the "window" object to capture the backbutton event
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
Usage in a component
import { Component, HostListener } from '@angular/core';
export class myComponent {
constructor() {}
// Prevent from exiting app by hook into document backbutton
@HostListener('document:backbutton', ['$event'])
onPopState(event) {
alert('Start page');
}
}
answered Jul 9 '17 at 6:46
KarlKarl
2,13321522
2,13321522
add a comment |
add a comment |
step 1: Import Locatoion from angular commmon
import {Location} from "@angular/common";
step 2: Initialise in constructor
private commonService: CommonService
step 3: Add function in ngOnInit of the respective coponent,
this.location.subscribe(currentLocation => {
if (currentLocation.url === '*/basic-info*') {
window.onpopstate = function (event) {
history.go(1);
}
}
});
Note: Here /basic-info will be replaced by your path.
If first time it is not working, try adding outside subscribe,
let currentUrl = window.location.href;
let tmpVar = currentUrl.includes('/basic-info');
if (currentUrl.includes('/basic-info')) {
window.onpopstate = function (event) {
history.go(1);
}
}
add a comment |
step 1: Import Locatoion from angular commmon
import {Location} from "@angular/common";
step 2: Initialise in constructor
private commonService: CommonService
step 3: Add function in ngOnInit of the respective coponent,
this.location.subscribe(currentLocation => {
if (currentLocation.url === '*/basic-info*') {
window.onpopstate = function (event) {
history.go(1);
}
}
});
Note: Here /basic-info will be replaced by your path.
If first time it is not working, try adding outside subscribe,
let currentUrl = window.location.href;
let tmpVar = currentUrl.includes('/basic-info');
if (currentUrl.includes('/basic-info')) {
window.onpopstate = function (event) {
history.go(1);
}
}
add a comment |
step 1: Import Locatoion from angular commmon
import {Location} from "@angular/common";
step 2: Initialise in constructor
private commonService: CommonService
step 3: Add function in ngOnInit of the respective coponent,
this.location.subscribe(currentLocation => {
if (currentLocation.url === '*/basic-info*') {
window.onpopstate = function (event) {
history.go(1);
}
}
});
Note: Here /basic-info will be replaced by your path.
If first time it is not working, try adding outside subscribe,
let currentUrl = window.location.href;
let tmpVar = currentUrl.includes('/basic-info');
if (currentUrl.includes('/basic-info')) {
window.onpopstate = function (event) {
history.go(1);
}
}
step 1: Import Locatoion from angular commmon
import {Location} from "@angular/common";
step 2: Initialise in constructor
private commonService: CommonService
step 3: Add function in ngOnInit of the respective coponent,
this.location.subscribe(currentLocation => {
if (currentLocation.url === '*/basic-info*') {
window.onpopstate = function (event) {
history.go(1);
}
}
});
Note: Here /basic-info will be replaced by your path.
If first time it is not working, try adding outside subscribe,
let currentUrl = window.location.href;
let tmpVar = currentUrl.includes('/basic-info');
if (currentUrl.includes('/basic-info')) {
window.onpopstate = function (event) {
history.go(1);
}
}
answered Apr 11 '18 at 16:57
saravana vasaravana va
261312
261312
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41035672%2fdisable-back-page-button-in-browser%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown