Angularjs ui路由器需要默认加载子状态,类似于主页

时间:2016-10-24 08:45:38

标签: angularjs angular-ui-router angular-ui-bootstrap angular-ui

我正在使用angularjs ui路由器,我需要默认加载子状态(即' dashboardParent.dashboard')。

$stateProvider.state('dashboardParent', {
        abstract: true,
        url: '/dashboard',
        templateUrl: 'app/views/dashboard/dashboard-parent.html',
        controller: 'DashboardParentController'
    }).state('dashboardParent.dashboard', {
        url: '/',
        templateUrl: 'app/views/dashboard/dashboard.html',
        controller: 'DashboardController'
    })

一般来说,我们所做的是home状态与网址(" /")从那里我们导航到其他状态,让我们说'dashboardParent.dashboard'。但在这里,我没有任何home州。当我启动应用程序时,我希望加载dashboardParent.dashboard状态。如何实现它。

如果我添加另一个状态home并提供导航到状态'dashboardParent.dashboard'的链接,则表示正常加载。但我的要求是我没有任何家庭状态,而是我需要默认加载'dashboardParent.dashboard'。如何实现呢?

1 个答案:

答案 0 :(得分:0)

以下代码可以帮助您:

// if the path doesn't match any of the urls you configured
// otherwise will take care of routing the user to the specified url
$urlRouterProvider.otherwise('/');

参考:URL-Routing of ui-router

注意:不要忘记注入$urlRouterProvider服务。