I have a $urlRouterProvider.otherwise(’/login’) in the routes so if it does not recognize the URL it goes back to the login page. after the user logins in I have a state.go() to another page in that page I have a button when clicked goes to a state.go() to another page. The first time the button is clicked it redirects back to the login page BUT also runs the controller for the state that matched the URL in the state.go() and after I login and try to access that page it goes to that page but does not load everything correctly. Not sure why its redirecting me back to the login page if it matches a URL in the routes. I attached the code for routes.js and a snippet of the second state.go() statement because it would be a lot of code to copy the whole thing in.
Routes.js:
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
})
.state('menu.map', {
url: '/page1',
views: {
'side-menu21': {
templateUrl: 'templates/map.html',
controller: 'MapCtrl' //'homeCtrl'
}
}
})
.state('menu.home', {
url: '/page2',
views: {
'side-menu21': {
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
}
}
})
.state('menu.cloud', {
url: '/page3',
views: {
'side-menu21': {
templateUrl: 'templates/cloud.html',
controller: 'cloudCtrl'
}
}
})
.state('menu', {
url: '/side-menu21',
templateUrl: 'templates/menu.html',
abstract:true
})
$urlRouterProvider.otherwise('/login')
});
controller.js:
$scope.acceptYes = function () {
var acceptURL = API_URL + "accept";
var acceptData = "userID=" + user;
$http.put(acceptURL, acceptData, { headers: { 'Content-Type': 'application/x-www-form-urlencoded'} }).then(
function (res) {
console.log("Answer: " + res.data);
// Move to map with driving directions
$state.go('menu.map');