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("/")
}
})
});
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("/")
}
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With