本文介绍了如何设置默认 URL/路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施 AngularUI 的路由,但似乎缺少有关如何配置默认 URL 的信息.似乎下面的代码会将用户默认为 /dashboard/tree 但如果我刷新页面,该 url 会附加另一个 /dashboard,所以我最终得到 /dashboard/dashboard/dashboard/dashboard/tree.

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.

如何在用户第一次访问页面时正确设置默认 URL 而不会出现此附加问题?

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

推荐答案

信不信由你,这可能是 angular 1.1.5 中的一个错误/功能(重新加载向 url 添加内容).

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>

这篇关于如何设置默认 URL/路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:28