I've an SPA with rails api on backend and angular as front-end framework.
I'm using stateProviders,
$urlRouterProvider for managing states in my SPA I'm facing a small problem with ui-router. Whenever I refresh by hitting Comand+R from Mac/Linux or F5 from Windows. It goes to the state where it was refreshed and right after it redirects to the \dashboard.
I want to stop this redirect I've read some articles, related question, and some github issues too but nothing made me successful.
Some of references where I did consult.
Angular-ui-router state with $stateParams always redirects to $urlRouteProvider.otherwise
AngularJS : angular-ui-router always redirects to $urlRouterProvider.otherwise location
https://github.com/angular-ui/ui-router/wiki/URL-Routing
After digging into those.
Here is my ui-router code:
app.coffee
'use strict'
$stateProvider
.state('app',
url: '/'
templateUrl: 'shared/app.html'
abstract: true
resolve:
company: ['CompanyResource', '$rootScope', (CompanyResource, $rootScope) ->
CompanyResource.current().$promise.then (company)->
$rootScope.app.company = company
]
user: ['Auth', '$state', '$rootScope', (Auth, $state, $rootScope)->
if !$rootScope.signedin
Auth.currentUser()
.catch ->
$state.go('login.signin')
]
)
.state('login',
template: '<div ui-view></div>'
abstract: true
resolve:
company: ['CompanyResource', '$rootScope', (CompanyResource, $rootScope) ->
CompanyResource.current().$promise.then (company)->
$rootScope.app.company = company
]
)
.state('login.signin',
url: '/signin'
templateUrl: 'templates/signin.html'
controller: 'SigninCtrl'
controllerAs: 'signin_ctrl'
)
.state('app.dashboard',
url: 'dashboard'
templateUrl: 'templates/admin/dashboard.html'
title: 'Dashboard'
controller: 'DashboardCtrl'
controllerAs: 'dashboard_ctrl'
resolve: []
)
.state('app.settings',
url: 'settings'
templateUrl: 'templates/admin/settings/base.html'
controller: 'SettingsBaseCtrl'
controllerAs: 'settings_ctrl'
resolve:
settings: ['AdminSettingsResource', (AdminSettingsResource) ->
AdminSettingsResource.query().$promise
]
)
$urlRouterProvider.otherwise '/dashboard'
angular
.module('MYAPP', [
'templates'
'ngResource'
'ngAnimate'
'ngCookies'
'ngStorage'
'ngSanitize'
'ngTouch'
'ui.router'
'ui.bootstrap'
'duScroll'
'angularMoment'
'Devise'
])
.config(['$compileProvider', ($compileProvider)->
$compileProvider.debugInfoEnabled(true)
])
.run(['$rootScope', '$state', '$stateParams', ($rootScope, $state, $stateParams) ->
FastClick.attach document.body
$rootScope.$state = $state
$rootScope.$stateParams = $stateParams
])
.config([
'$stateProvider'
'$urlRouterProvider'
])
otherwisecan be passed a function which might help you track down the issue..$promiseon all service calls, although an orthogonal issue, indicates incorrect use of$q.derfer()and ofPromisesin general. This will likely bite you and indicates you are probably writing more code than you have to. Service methods should return aPromise, not aDeferred.deffersuggestion But my issue is different thanks for your advice although.. I have converted tojavascriptand created agistfor you please look into. gist.github.com/mutafaf/3ede1adbcc53a60df93177d3da652d67$qdependencies, ripping out your 8+module('app', [...])dependencies. That is not even close to a minimal repro.