angularjs - angular + ui-router : event.preventDefault(); prevent all the app states from working -
i want evaluate user when app start if it's authenticated change state "categories" if not go "land" state. reached using $statechangestart in run block :
.run(function($ionicplatform, dscachefactory, $rootscope, $auth, $state) { $ionicplatform.ready(function() { // hide accessory bar default (remove show accessory bar above keyboard // form inputs) if (window.cordova && window.cordova.plugins.keyboard) { cordova.plugins.keyboard.hidekeyboardaccessorybar(true); } if (window.statusbar) { // org.apache.cordova.statusbar required statusbar.styledefault(); } }); $rootscope.$on('$statechangestart', function (event, tostate) { if (!$auth.isauthenticated() && tostate.name !== 'land') { event.preventdefault(); $state.go('land'); } }); }) and if it's authenticated:
$urlrouterprovider.otherwise('app/categories'); every thing works fine user evaluated correctly but, clicking on in app taking me land state. idea why! router code :
.config(function($stateprovider, $urlrouterprovider, $authprovider, $ionicappprovider, api_url) { $stateprovider .state('app', { url: "/app", abstract: true, templateurl: "templates/menu.html", controller: 'appctrl' }) .state('land', { url: '/land', templateurl: 'templates/land.html', controller: 'landctrl' }) .state('signup', { url: '/sign-up', templateurl: 'templates/sign-up.html', controller: 'signupctrl' }) .state('signin', { url: '/sign-in', templateurl: 'templates/sign-in.html', controller: 'signinctrl' }) .state('app.categories', { url: '/categories', views: { 'menucontent': { templateurl: 'templates/categories.html', controller: 'categoriesctrl', } } });
Comments
Post a Comment