How to redirect users if there is no Internet connection in Ionic framework?

I want to redirect users to a different page when they're not connected to the Internet.

My only question is why this is working:

if (window.Connection) {
    if(navigator.connection.type == Connection.NONE) {
        alert("Please connect to internet");
    }
}

and this is not

if (window.Connection) {
    if(navigator.connection.type == Connection.NONE) {
        $scope.state.go('offline');  
    }
}

Because you're using $state the wrong way. Instead of this:

$scope.state.go('offline'); 

You should do it like this:

$state.go('offline'); 

Remember to inject $state in your controller. More information about $state from official docs.

By Remember to inject $state in your controller I'm referring, for example, to this:

app.controller('ctrl', function ($scope, $state) {
    $scope.changeState = function () {
        $state.go('someplaceNice');
    };
});