Angular ionic 4 navigateRoot()显示硬件后退按钮
我有一个登录页面,当身份验证成功时,它会将用户导航到主页,为此,我使用angular router的Angular ionic 4 navigateRoot()显示硬件后退按钮,angular,ionic-framework,ionic4,router,Angular,Ionic Framework,Ionic4,Router,我有一个登录页面,当身份验证成功时,它会将用户导航到主页,为此,我使用angular router的navigateRoot()方法 但当我这样做时,“硬件后退”按钮仍然有效,并允许我返回主页 我做错了什么,还是这是一个错误? 以下是用于导航的代码: if (user) { this.buttonDisabled = false; this.loggingIn = false; this.navCtrl.navigateRoot('/home'); } 我的路线是这样定
navigateRoot()
方法
但当我这样做时,“硬件后退”按钮仍然有效,并允许我返回主页
我做错了什么,还是这是一个错误?
以下是用于导航的代码:
if (user) {
this.buttonDisabled = false;
this.loggingIn = false;
this.navCtrl.navigateRoot('/home');
}
我的路线是这样定义的:
const routes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'home',
loadChildren: './pages/home/home.module#HomePageModule',
},
{
path: 'list',
loadChildren: './pages/list/list.module#ListPageModule'
},
{
path: 'login',
loadChildren: './pages/login/login.module#LoginPageModule'
},
{ path: 'task', loadChildren: './pages/task/task.module#TaskPageModule' },
{ path: 'door', loadChildren: './pages/door/door.module#DoorPageModule' },
{ path: 'work', loadChildren: './pages/work/work.module#WorkPageModule' },
{ path: 'address-search', loadChildren: './modals/address-search/address-search.module#AddressSearchPageModule' },
{ path: 'parts-list', loadChildren: './modals/parts-list/parts-list.module#PartsListPageModule' }
];
环境信息:
Ionic:
ionic (Ionic CLI) : 4.2.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.6.2
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 13 other plugins)
System:
ios-deploy : 1.9.4
ios-sim : 8.0.0
NodeJS : v12.9.0 (/usr/local/Cellar/node/12.9.0/bin/node)
npm : 6.11.2
OS : macOS
Xcode : Xcode 10.3 Build version 10G8
我希望我不是唯一一个有这个问题的人,这让我发疯
提前感谢在主页上,按如下方式处理硬件后退按钮以关闭应用程序: 例如 编辑: 如果这不起作用,请执行以下操作:
this.platform.backButton.subscribeWithPriority(1, () => {
//on or the other will work depending on hardware
navigator['app'].exitApp();
});
这将关闭您在主页上的应用程序。我遇到的问题与您描述的完全一样。在我的app.component.html文件中,我缺少
周围的
包装。我把它放进去,它把它修好了 我觉得这是一个解决办法,而不是一个有效的解决办法是的,这是一个解决办法。我认为在ionic 4中,它们已经改变了navCtrl
的行为。尝试实施此解决方案。我已经在我的应用程序中实现了这一点,它工作得非常完美。你有没有想过?我的一个项目展示了这种行为,而另一个(具有相同的离子信息)没有。
this.platform.backButton.subscribeWithPriority(1, () => {
//on or the other will work depending on hardware
navigator['app'].exitApp();
});