From 3fe0b473f7ff577edf3910210b3036f6b8754ba2 Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Thu, 13 Aug 2020 19:54:33 +0200
Subject: [PATCH] [fix] When open page by URI, remove the back view only when =
 app.home

---
 www/js/controllers/home-controllers.js |  6 ++++--
 www/js/platform.js                     | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/www/js/controllers/home-controllers.js b/www/js/controllers/home-controllers.js
index 9fd026656..a2362a37a 100644
--- a/www/js/controllers/home-controllers.js
+++ b/www/js/controllers/home-controllers.js
@@ -26,8 +26,8 @@ angular.module('cesium.home.controllers', ['cesium.platform', 'cesium.services']
   .controller('HomeCtrl', HomeController)
 ;
 
-function HomeController($scope, $state, $timeout, $ionicHistory, $translate, $http, $q, UIUtils, BMA,
-                        csConfig, csCache, csPlatform, csCurrency, csSettings, csHttp) {
+function HomeController($scope, $state, $timeout, $ionicHistory, $translate, $http, $q, $location,
+                        UIUtils, BMA, csConfig, csCache, csPlatform, csCurrency, csSettings) {
   'ngInject';
 
   $scope.loading = true;
@@ -179,6 +179,8 @@ function HomeController($scope, $state, $timeout, $ionicHistory, $translate, $ht
       delete stateParams.uri;
       delete stateParams.error;
 
+      $location.search(stateParams).replace();
+
       // Update location href
       $ionicHistory.nextViewOptions({
         disableAnimate: true,
diff --git a/www/js/platform.js b/www/js/platform.js
index 24be8e508..0ef30a900 100644
--- a/www/js/platform.js
+++ b/www/js/platform.js
@@ -275,15 +275,20 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
       }
 
       if (state) {
+
+        var fromHomeState = $state.current && $state.current.name === 'app.home';
+
         // Open the state, after cleaning current location URI
         return $state.go(state, stateParams, {
           reload: true
         })
           .then(function () {
-            // This is need to make back button working again
-            return $timeout(function () {
-              if ($ionicHistory.backView()) $ionicHistory.removeBackView();
-            }, 400);
+            if (fromHomeState) {
+              // This is need to make back button working again
+              return $timeout(function () {
+                if ($ionicHistory.backView()) $ionicHistory.removeBackView();
+              }, 400);
+            }
           });
       } else {
         console.error("[home] Unknown URI format: " + uri);
@@ -311,7 +316,7 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
         BMA.api.node.on.restart($rootScope, restart, this),
 
         // Listen for new intent
-        Device.api.intent.on.new($rootScope, handleOpenUri, this)
+        Device.api.intent.on.new($rootScope, openUri, this)
       ];
     }
 
-- 
GitLab