Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run function and location path issue

Tags:

angularjs

I'm using a run function to conditionally redirect people to a page , regarding their login state. redirection depending on user state works pretty well , but after the redirection , navigate between page won't work , when i click to navigate i stay in the same page. this is what my code looks like , can anyone help me?

var app = angular.module( 'YourApp', [ 'ngMaterial', "ngRoute" ])
app.config(($routeProvider, $mdThemingProvider, $mdIconProvider, $mdDateLocaleProvider) => {

  $mdIconProvider
    .iconSet("lala", 'assets/logo/ic_keyboard_arrow_left_white_48px.svg', 24)
    .iconSet("social", 'img/icons/sets/social-icons.svg', 24);

  $mdThemingProvider.theme('primary')
      .primaryPalette('brown')
      .accentPalette('yellow');

      $mdDateLocaleProvider.formatDate = function(date) {
    return moment(date).format('DD-MM-YYYY');
 };


  $routeProvider
  .when("/", {
    templateUrl: "home.html",
    controller: "myCtrl"
  }).when("/voyages", {
    templateUrl: "voyages.html",
    controller: "voyageCtrl"
  }).when("/bagages", {
    templateUrl: "bagages.html",
    controller: "BagagesCtrl"
  }).when("/login",{
    templateUrl: "login.html",
    controller: "loginCrtl"
  }).when("/voyageID/:voyageid" , {
    templateUrl: "voyageID.html",
    controller: "voyageIDCtrl"
  })
  .otherwise({
   redirectTo: '/'
});

})

.run(function($rootScope, $location) {
  var Parse = require('parse');
  Parse.initialize("CODE", "PIN");
  Parse.serverURL = 'https://stelimac.herokuapp.com/parse';
    $rootScope.$on("$routeChangeStart", (event) => {
      var currentUser = Parse.User.current();
        if (!currentUser) {
          $location.path("/login")
        } else {
         $location.path("/")
        }
    })
});
like image 527
PrinceZee Avatar asked Sep 30 '26 03:09

PrinceZee


1 Answers

change $location.path to $state.go

.run(function($rootScope, $state) {
      var Parse = require('parse');
      Parse.initialize("CODE", "PIN");
      Parse.serverURL = 'https://stelimac.herokuapp.com/parse';
        $rootScope.$on("$routeChangeStart", (event) => {
          var currentUser = Parse.User.current();
            if (!currentUser) {
              $state.go("/login")
            } else {
             $state.go("/")
            }
        })
    });
like image 168
Raghav Patel Avatar answered Oct 01 '26 22:10

Raghav Patel