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'
])