如何设置默认URL /路由?

时间:2022-06-30 11:20:55

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.

我正在实现AngularUI的路由,似乎缺少有关如何配置默认URL的内容。看起来下面的代码会将用户默认为/ dashboard / tree,但如果我刷新页面,则url会附加另一个/仪表板,因此我最终会使用/ 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?

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

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 个解决方案

#1


5  

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

信不信由你,这可能是角1.1.5中的错误/特征(重新加载添加到网址的东西)。

Try setting this in your head:

尝试在脑中设置:

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

#1


5  

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

信不信由你,这可能是角1.1.5中的错误/特征(重新加载添加到网址的东西)。

Try setting this in your head:

尝试在脑中设置:

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