没有urlRouterProvider.otherwise的ui路由

Routing doesn't occur if I don't include $urlRouterProvider.otherwise('/'); in the config.

my go app engine setting with gorilla is

r := mux.NewRouter()
r.HandleFunc(/admin, handleAdmin)

and angularjs config is;

angular.module('admin')
    .config(function($stateProvider, $urlRouterProvider) {
      $stateProvider.state('home', {
        url: '/',
        templateUrl: '/admin/index.html',
        controller: 'AdminController as admin'
      });
  //$urlRouterProvider.otherwise('/');
})

when I don't call $urlRouterProvider.othwerwise line, and I open http://localhost:8080/admin I expect to see admin/index.html, but I don't. I see it only if I navigate to http://localhost:8080/admin#/ manually. But if I add $urlRouterProvider.othwerwise option and go to http://localhost:8080/admin it redirects automatically to http://localhost:8080/admin#/ I don't think this is usual way to do it because I may want "otherwise" to route to a custom 404 page. What point do I miss?

By default, Angular adds the hashPrefix in front of urls. So when you navigate to http://localhost:8080/admin , You don't see index.html since you have not yet visited the url as defined in the angular's ui-router. You will have to navigate to http://localhost:8080/admin/#/ to actuall be in the / state of your application.

It is the same reason that your app doesn't work without the .otherwise(), since then it automatically redirects you to the / state later.

For a possible fix:

Inside your .config function:

// This is in your app module config.
$locationProvider.html5Mode(true);

And in your index.html:

// This is in your index.html head.
<base href="/" />

The problem is not with not having a declared otherwise.

The problem lays on your route. You're specifying the url to be '/', that means the state home is accessible only through http://localhost:8080/admin/ and NOT through http://localhost:8080/admin

What the otherwise does is. When you access the url http://localhost:8080/admin the router try to find a state that matches the url, but don't find it. So it redirects to http://localhost:8080/admin/ which matches with your home state.