Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic framework $state.go('app.home'); is adding back button on page where I want to go (how to remove it)?

I have app with sidebar menu. I am on second page and I am calling controller function which redirect me to first page using:

$state.go('app.home'); 

Problem is that on this page is now displayed back button next sidebar menu icon, see image below:

enter image description here

Could somebody tell me how to deny to add back button into pages which has assigned sidebar menu?

Thanks for any help.

app.js is with router config is following:

angular.module('Test', ['ionic', 'config', 'Test', 'LocalStorageModule'])  .run(function($ionicPlatform) {   $ionicPlatform.ready(function() {     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard     // for form inputs)     if(window.cordova && window.cordova.plugins.Keyboard) {       cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);     }     if(window.StatusBar) {       // org.apache.cordova.statusbar required       StatusBar.styleDefault();     }   }); })  .config(function($stateProvider, $urlRouterProvider, localStorageServiceProvider) {    localStorageServiceProvider      .setPrefix('max_relax');    $stateProvider      .state('app', {       url: '/app',       abstract: true,       templateUrl: 'templates/menu.html',       controller: 'AppCtrl'     })      .state('app.home', {       url: '/home',       views: {         'menuContent' :{           templateUrl: 'templates/home.html',           controller: 'HomeCtrl'         }       }     })      .state('app.saved', {       url: '/saved',       views: {         'menuContent' :{           templateUrl: 'templates/saved.html',           controller: 'SavedCtrl'         }       }     })     .state('app.settings', {       url: '/settings',       views: {         'menuContent' :{           templateUrl: 'templates/settings.html',           controller: 'SettingsCtrl'         }       }     });   // if none of the above states are matched, use this as the fallback   $urlRouterProvider.otherwise('/app/home'); }); 

Edit:

Added menu template:

<ion-side-menus>    <ion-pane ion-side-menu-content>     <ion-nav-bar class="bar-stable">       <ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>     </ion-nav-bar>     <ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>   </ion-pane>    <ion-side-menu side="left">     <header class="bar bar-header bar-stable">       <h1 class="title">Menu</h1>     </header>     <ion-content class="has-header">       <ion-list>         <ion-item nav-clear menu-close href="#/app/home">           Home         </ion-item>         <ion-item nav-clear menu-close href="#/app/saved">           Saved         </ion-item>         <ion-item nav-clear menu-close href="#/app/settings">           Settings         </ion-item>        </ion-list>     </ion-content>   </ion-side-menu> </ion-side-menus> 
like image 677
redrom Avatar asked Jan 13 '15 20:01

redrom


People also ask

How do you use the back button in ionic?

The hardware back button is found on most Android devices. In native applications it can be used to close modals, navigate to the previous view, exit an app, and more. By default in Ionic, when the back button is pressed, the current view will be popped off the navigation stack, and the previous view will be displayed.

How do you add the Back button in ionic 4?

Ionic back button example Here is a screenshot of the slot attribute used ionic back button. The slot can be left or right and by default, it is left. Let add back button for about page template. Let add the slot right attribute for the contact page template.

How do you use the back button in ionic 5?

The back button navigates back in the app's history upon click. It is smart enough to know what to render based on the mode and when to show based on the navigation stack. To change what is displayed in the back button, use the text and icon properties.

How do you disable hardware back button at particular page in ionic 3?

If you only want to prevent the application from closing when the user presses the back button on the root page, you can use the navExitApp configuration option. You set it as an argument to the IonicModule import: @NgModule({ // ... imports: [ BrowserModule, IonicModule.


1 Answers

Use $ionicHistory in your controller before calling $state.go('app.home').

.controller('HomeCtrl', function($scope,...,$ionicHistory) {   ...   $ionicHistory.nextViewOptions({     disableBack: true   });    $state.go('app.home'); }); 
like image 89
Bellu Avatar answered Sep 19 '22 15:09

Bellu