{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/1985","labels_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1985/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1985/comments","events_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1985/events","html_url":"https://github.com/angular-ui/ui-router/issues/1985","id":79750747,"number":1985,"title":"ui-router with html5mode(true) page refresh issue","user":{"login":"reggieboyYEAH","id":7448059,"avatar_url":"https://avatars.githubusercontent.com/u/7448059?v=3","gravatar_id":"","url":"https://api.github.com/users/reggieboyYEAH","html_url":"https://github.com/reggieboyYEAH","followers_url":"https://api.github.com/users/reggieboyYEAH/followers","following_url":"https://api.github.com/users/reggieboyYEAH/following{/other_user}","gists_url":"https://api.github.com/users/reggieboyYEAH/gists{/gist_id}","starred_url":"https://api.github.com/users/reggieboyYEAH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reggieboyYEAH/subscriptions","organizations_url":"https://api.github.com/users/reggieboyYEAH/orgs","repos_url":"https://api.github.com/users/reggieboyYEAH/repos","events_url":"https://api.github.com/users/reggieboyYEAH/events{/privacy}","received_events_url":"https://api.github.com/users/reggieboyYEAH/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-23T06:26:15Z","updated_at":"2015-05-27T01:48:38Z","closed_at":null,"body":"I have an app that uses **angular-ui-router** with **html5mode(true)**. Everything seems to work fine when running and routing to other states.\r\n\r\nMy default state is *app/calendar* which is set during module.run()\r\n\r\n\r\nBut when i refresh the page while i'm currently in other routes(lets say *app/profile*) it takes me back to app/calendar.\r\n\r\n\r\nDebugging i noticed that the $state.current is always empty after i refresh the page\r\n\r\n    Object {name: \"\", url: \"^\", views: null, abstract: true}\r\n\r\nif only the $state.current has value i can just transistion to the current state.\r\n\r\nIs there anything that i am missing?\r\n\r\nHopefully someone can help.\r\n\r\nMy **server routing** looks like\r\n\r\n    app.get('/:var(/|app/calendar|app/customers|app/profile|app/settings)?', function(req, res) {\r\n        res.sendFile('/app/main/main.html',{ root: '../Appt/public' });\r\n    });\r\n\r\ni'm always serving the same file.\r\n\r\nand my **front-end state configuration** \r\n\r\n    (\r\n        function()\r\n        {\r\n            angular.module('Appt.Main').config(['$stateProvider','$locationProvider',function($stateProvider,$locationProvider)\r\n            {\r\n                $locationProvider.html5Mode(true);\r\n    \r\n                var calendar = {\r\n                        name: 'calendar',\r\n                        url: 'app/calendar',\r\n                        controller: 'Appt.Main.CalendarController',\r\n                        controllerAs: 'calendar',\r\n                        templateUrl: '/app/main/calendar/calendar.html'\r\n                    },\r\n                    customers = {\r\n                        name: 'customers',\r\n                        url: 'app/customers',\r\n                        controller : 'Appt.Main.CustomersController',\r\n                        controllerAs : 'customers',\r\n                        templateUrl : '/app/main/customers/customers.html'\r\n                    },\r\n                    profile = {\r\n                        name: 'profile',\r\n                        url: 'app/profile',\r\n                        controller : 'Appt.Main.ProfileController',\r\n                        controllerAs : 'profile',\r\n                        templateUrl : '/app/main/profile/profile.html'\r\n                    },\r\n                    settings = {\r\n                        name: 'settings',\r\n                        url: 'app/settings',\r\n                        controller : 'Appt.Main.SettingsController',\r\n                        controllerAs : 'settings',\r\n                        templateUrl : '/app/main/settings/settings.html'\r\n                    };\r\n    \r\n    \r\n                $stateProvider.state(calendar);\r\n                $stateProvider.state(customers);\r\n                $stateProvider.state(profile);\r\n                $stateProvider.state(settings);\r\n    \r\n            }]);\r\n    \r\n        }\r\n    )();\r\n\r\n\r\nMy module.run \r\n\r\n\r\n\r\n    (\r\n        function()\r\n        {\r\n            'use strict';\r\n    \r\n            angular.module('Appt.Main',['ngRoute','ui.router','Appt.Directives'])\r\n                .run(['$state','$stateParams', function ($state,$stateParams) {\r\n                    console.log('Appt.Main is now running')\r\n    \r\n    \r\n                    console.log($state.current);\r\n                    console.log($stateParams);\r\n    \r\n                    $state.transitionTo('calendar');\r\n    \r\n    \r\n                }])\r\n        }\r\n    )();"},"comment":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/comments/105717911","html_url":"https://github.com/angular-ui/ui-router/issues/1985#issuecomment-105717911","issue_url":"https://api.github.com/repos/angular-ui/ui-router/issues/1985","id":105717911,"user":{"login":"reggieboyYEAH","id":7448059,"avatar_url":"https://avatars.githubusercontent.com/u/7448059?v=3","gravatar_id":"","url":"https://api.github.com/users/reggieboyYEAH","html_url":"https://github.com/reggieboyYEAH","followers_url":"https://api.github.com/users/reggieboyYEAH/followers","following_url":"https://api.github.com/users/reggieboyYEAH/following{/other_user}","gists_url":"https://api.github.com/users/reggieboyYEAH/gists{/gist_id}","starred_url":"https://api.github.com/users/reggieboyYEAH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reggieboyYEAH/subscriptions","organizations_url":"https://api.github.com/users/reggieboyYEAH/orgs","repos_url":"https://api.github.com/users/reggieboyYEAH/repos","events_url":"https://api.github.com/users/reggieboyYEAH/events{/privacy}","received_events_url":"https://api.github.com/users/reggieboyYEAH/received_events","type":"User","site_admin":false},"created_at":"2015-05-27T01:48:38Z","updated_at":"2015-05-27T01:48:38Z","body":"Hello @eddiemonge , I am using express in the backend. \r\n\r\nand here is my code, basically i am returning the same html file for the matching routes\r\n\r\napp.get('/:var(/|app/calendar|app/customers|app/profile|app/settings)?', function(req, res) {\r\n    res.sendFile('/app/main/main.html',{ root: '../Appt/public' });\r\n});\r\n\r\n\r\ni tried implementing $stateChangeSuccess  inside the run block but that event doesnt happen until i call $state.go() inside the run block.\r\n\r\nSo i ended up with a solution like this\r\n\r\n        angular.module('Appt.Main',['ui.router','Appt.Directives'])\r\n            .run(['$rootScope','$state','$stateParams','$location',function ($rootScope,$state,$stateParams,$location) {\r\n                console.log('Appt.Main is now running')\r\n\r\n                $rootScope.$state = $state;\r\n                $rootScope.$stateParams = $stateParams;\r\n\r\n\r\n                //Handle page refresh\r\n                //TODO: possibly change this to if else statement to handle parameters with regex\r\n                var path = $location.path();\r\n                \r\n                switch(path) {\r\n                    case '/app/calendar':\r\n                        $state.go('calendar');\r\n                        break;\r\n                \r\n                    case '/app/customers':\r\n                        $state.go('customers');\r\n                        break;\r\n                }\r\n\r\n\r\n\r\n\r\n                $rootScope.$on('$stateChangeStart', function (event, toState) {\r\n                    console.log('$stateChangeStart');\r\n                    console.log(toState);\r\n                });\r\n\r\n                $rootScope.$on('$locationChangeSuccess', function(e) {\r\n                    console.log('$locationChangeSuccess');\r\n                });\r\n\r\n\r\n                $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){\r\n                    console.log(event);\r\n                    console.log(toState);\r\n                });\r\n\r\n            }])\r\n              \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}}