1

I have the following configuration in my AngularJS App:

angular
    .module('MyApp')
    .config(['$stateProvider', '$urlRouterProvider', '$locationProvider', 
        function($stateProvider, $urlRouterProvider, $locationProvider) {
            $urlRouterProvider.otherwise('start');

            $stateProvider
                .state('start', {
                    url : '/start',
                    templateUrl : 'views/start.html',
                    controller : 'AppCtrl'
                })
                .state('quotation', {
                    url : '/quotation',
                    templateUrl : 'views/quotation.html',
                    controller : 'AppCtrl'
                })
                .state('loading', {
                    url : '/loading',
                    templateUrl : 'views/loading.html'
                });
        }]);

When the user type http://example.net the "start" view is loaded good http://example.net/#/start, but if the user type directly http://example.net/#/quotation the "quotation" view is loaded and there I have some problems, because the call from start to quotation load some values (via REST API), so .. If the user type directly that view, the loaded was not correct.

How I can avoid direct access to another views?

Candres
  • 385
  • 2
  • 5
  • 18
  • this is similar to implementing, say, authentication checks. For example: http://stackoverflow.com/questions/22537311/angular-ui-router-login-authentication – akonsu Oct 26 '14 at 16:21
  • Are you build a mobile app or web app? – shamon shamsudeen Oct 26 '14 at 16:21
  • You can check on each state change if there is any exception thrown. If so then handle it by either going to starting page or showing some error message – dchhetri Oct 26 '14 at 17:03

1 Answers1

0

In star page load change set the $rootscope.allowpage=true then use the following code, it will check whether $rootscope.allowpage is set to true or not , if $rootscope.allowpage not true it will redirect to start page

angular.module('MyApp'['ngRoute','ui.bootstrap','timer'])
.run(function($rootScope,$location) {
        $rootScope.$on( "$routeChangeStart", function(event, next, current) {
              if ( $rootScope.allowpage!= true ) {
                    $location.path('start');
              }});
});
Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54