1

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?

1
  • 1
    Add a path parameter to main.error404 state. This will cause the state to be reloaded when the parameter changes Commented Jan 21, 2015 at 21:45

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.