How to set default URL/route?

不想你离开。 提交于 2019-12-14 00:21:51

问题


I'm implementing AngularUI's routing and appear to be missing something about how to configure a default URL. It seems like the below code would default the user to /dashboard/tree but if I refresh the page, the url appends another /dashboard, so I end up with /dashboard/dashboard/dashboard/dashboard/tree.

How can I properly set the default URL without having this appending issue when the user first visits the page?

config(['$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider) {
    $urlRouterProvider.otherwise('/dashboard/tree');

    /* URL mappings */
    $stateProvider.
        state('dashboard', {
            url: '/dashboard',
            views: {
                'page': {
                    templateUrl: '/partials/admin/dashboard.htm'
                }
            }
        }).
        state('dashboard.tree', {
            url: '/tree',
            views: {
                'content': {
                    templateUrl: '/partials/admin/tree-overview.htm'
                }
            }
        });
}])

回答1:


Believe it or not, this is probably a bug/feature in angular 1.1.5 (reloads add stuff to the url).

Try setting this in your head:

<base href="/"></base>


来源:https://stackoverflow.com/questions/17200231/how-to-set-default-url-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!