ForceUser
ForceUser

Reputation: 1119

Is there way to reload specific ui-view with angular-ui-router?

Here is my test application http://plnkr.co/edit/OjpZ1h?p=preview

I have 404 error page state, and i need to display path of requested page if this page not exists. Here code of redirection:

$urlRouterProvider.otherwise(function($injector, $location){
    var lastPath = $location.path();
    $injector.invoke(['$state', function($state) {
        var params = angular.copy($state.params);
        $state.go('main.error404',params, {location: false});
    }]);
    return lastPath;
});

All works fine except the situation when app already in error state and i'm going to next page that also don't exists.

In this case reload doesn't happens and it displays path of the last page. If i change this code to

$state.go('main.error404',params, {reload: true,location: false});

then is displays right path but all views are reloading, it looks very nasty with animation.

Is there way to reload specific ui-view with angular-ui-router?

Upvotes: 1

Views: 1358

Answers (1)

ForceUser
ForceUser

Reputation: 1119

Thanks to Chris T comment, i rewrote it like that:

   $stateProvider
   .state('main.error404',{
      url: '/404/{path}',
      views: {
        "page@": {
          templateUrl: "error.html",
          controller: function($scope,$location,$state){
            $scope.page = $state.params.path;
          }
        }
      }
    });

    $urlRouterProvider.otherwise(function($injector, $location){
        var lastPath = $location.path();
        $injector.invoke(['$state',function($state) {
            var params = angular.copy($state.params);
            params.path = lastPath;
            $state.go('main.error404',params, {location: false});
        }]);
        return lastPath;
    });

State reloads every time path parameter changes

Upvotes: 1

Related Questions