Native back button on device redirects back from intermediate page

224 Views Asked by At

I have an endpoint (say /xyz) which on getting hit from the home page redirects to another page (say /abc) and opens up a webview in the app. When I click the native back button on the device from the webview, again the same intermediate endpoint '/xyz' is hit and it redirects me back to the webview endpoint (/abc) and it goes in an infinite loop. However I want the back button to take me to the home page.

I'm using window.location.replace('/abc') to redirect from /xyz but it's not helping. I tried window.location.href = url and that didn't help either.

Test1.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
    when('/xyz', {
        controller:'TestCtrl',
        template:' '
    }).
    when('/pqr', {
        controller:'Test2Ctrl',
        templateUrl:'/templates/pqr'
    });
}]);


Test1.controller('TestCtrl', [
    '$window', '$location',
    function(
    $window, $location) {
        var redirectTo = function() {
           window.location.replace('/abc');
        }
    redirectTo();
}]);

So, it correctly redirects to the endpoint '/abc' but on clicking the back button on the device from /abc, it goes back to '/xyz' and then redirects back to '/abc'. I want it to go back to the home page after clicking the back button from the webview in the app. Also, the back button redirects to the homepage on the browser. This issue is only on the native back button on the device.

0

There are 0 best solutions below