问题
does anyone know how to disable the back swipe after navigating to a new page?
I read this: http://docs.nativescript.org/angular/core-concepts/angular-navigation#clearing-page-navigation-history
Clearing Page Navigation History In NativeScript's page navigation, you have the option to navigate to another page and clear the page navigation history. This means that the user will not be able to go back using the back button (or swipe back in iOS). This is useful in scenarios where you have a login page and you don't want users to be able go go back to it once logged in. But I want to go back to login page when the user clicked logout.
I have 2 pages, LoginPage and FirstPage. Im using RouterExtensions. so this.nav.navigate([“/firstPage"], { clearHistory: true}); this works. On second page i have a button that goes to this.nav.navigate([“/”]) (so back to the login page). But I get
Aug 11 19:30:26 antons-MBP appname[62814]: CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:421:23: Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'cacheItem.reusedRoute')
回答1:
I tested clearHistory
while navigating to new page and it seems that everything work as expected. Could you verify, whether you are using latest CLI and modules. You could find instructions here, where have been described how to upgrade to latest NativeScript. In regard to that it you need to upgrade the tns-core-modules
and nativescript-angular
in exciting project you could follow the below described instructions.
tns plugin remove tns-core-modules
tns plugin add tns-core-modules@2.2.0
tns plugin remove nativescript-angular
tns plugin add nativescript-angular@0.3.0
You could also review my sample app here, how to use clearHistory
in NativeScript Angular.
回答2:
I was able to disable the swipe gesture per page by inserting the following code
constructor(private nav: RouterExtensions) {
this.nav.frame.ios.controller.interactivePopGestureRecognizer.enabled = false;
}
This way I don't have to modify the library, but the downside is that I have to re-enable "interactivePopGestureRecognizer" on every page that i want to the back swipe to work on.
来源:https://stackoverflow.com/questions/38907953/nativescript-angular-2-disable-swipe-back-on-ios