ui-router中的默认状态

时间:2017-02-07 17:43:05

标签: angularjs

我目前正在开发一个Web开发项目,我在实现 UI-router AngularJS )方面遇到了问题。

我想在页面加载时设置默认状态,也是子视图的默认状态。

如果我使用的abstract:true方法不是解决方案,因为当我想再次激活该状态时,它将无法实现。

2 个答案:

答案 0 :(得分:4)

希望这会给你回答你的问题

var App = angular.module('TechdefeatApp',['ui.router']);
App.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
    // For any unmatched url, send to /business
    $urlRouterProvider.otherwise("/")

    $stateProvider
    .state('/', {
        url: "/",
        templateUrl: "app/components/home/homeView.html",
        controller:"homeController"
    })
    .state('member', {
        url: "/member/:seo_url",
        templateUrl: "app/components/member/memberView.html",
        controller:"memberController"
    })
    .state('category', {
        url: "/category/:seo_url", 
        templateUrl: "app/components/category/categoryView.html",
        controller:"categoryController"
    })

}]);

答案 1 :(得分:1)

您需要在$ urlRouterProvider服务中使用, 在写完之后,首先注入这个服务 $urlRouterProvider.otherwise('/otherwise')

注意必须像往常一样在一个州上定义/ url:

$stateProvider .state("otherwise", { url : '/otherwise'...})

祝你好运!

相关问题