2016-11-18 53 views
0

我正在使用ui-router使用ui-router,并且收到以下错误消息。UI路由器无法解析状态错误消息

Error: Could not resolve 'static.about' from state 'static'

我不知道为什么。我想要实现的是在我的应用程序中有2个部分,静态部分,主页,关于,登录,注册和应用程序端,这些会像仪表板,用户配置文件等,我认为我需要设置我的ui-这样的路由器,

app 
.config(['$stateProvider', '$urlRouterProvider', 
function($stateProvider, $urlRouterProvider){ 
// any unknown URLS go to 404 
$urlRouterProvider.otherwise('/404'); 
// no route goes to index 
$urlRouterProvider.when('', '/home'); 
// use a state provider for routing 
$stateProvider 
    .state('static', { 
     url: '/home', 
     templateUrl: '', 
     views : { 
      header : { 
       templateUrl : 'app/components/shared/header.html' 
      }, 
      main: { 
       templateUrl : 'app/components/home/views/home.view.html' 
      } 
     } 
    }) 
    .state('static.about', { 
     // we'll add another state soon 
     url: '/about', 
     templateUrl: 'app/components/about/views/about.view.html', 
    }) 
    .state('app', { 
     abstract: true, 
     templateUrl: '' 
    }) 
    .state('app.dashboard', { 
     url: 'app/dashboard', 
     templateUrl : '', 
    })   
}]); 

但是,这会返回已经提到的错误。我想这样设置它的原因是,应用程序的两面也有非常不同的布局,所以我认为我应该能够将不同的布局插入我的?

然而,我遇到的最大的问题是错误,其次是链接正在生成,当我点击它应该去/ about,但是它会去/ home/about。

所有我想在早期阶段实现的是对我的“静态”的页面共享一个导航,并有可更换的主要部分,而对于“应用程序”页面有一个完全地新的布局/父模板

回答

0

您需要在子视图上设置parent属性。

.state('static.about', { 
    url   : '/about', 
    templateUrl : 'app/components/about/views/about.view.html', 
    parent  : 'static' 
}) 

另外检查这个问题的答案Angular ui-router : Parent & Child Views

我想,当你做$state.go(static.about)它只是去homepage,因为你正在做otherwise或类似的东西。

像:$urlRouterProvider.when('', '/home');

Angular-Ui-Router解决的主要route当事情是不行的。

另请注意,您在templateUrl的末尾添加了额外的,

0

上面的状态结构是可以的。我创建了一个plunker to demonstrate it here

在根状态“静态”我们只是不使用templateUrl ..它会跳过无论如何,因为我们定义views : {}

.state('static', { 
     url: '/home', 
     // we want to have views : {} so avoid this shorthand template 
     // templateUrl: '', 
     views: { 
     header: { 
      templateUrl : 'app/components/shared/header.html', 
     }, 
     main: { 
      templateUrl : 'app/components/home/views/home.view.html', 
     } 
     } 
    }) 

和一个孩子的状态'静态的。关于”可以使用'^'领先的标志,它的网址从根本

.state('static.about', { 
     // here we use a switch to inform - this url starts from root 
     //url: '/about', 
     url: '^/about', 
     templateUrl: 'app/components/about/views/about.view.html', 
    }) 

并与这些电话重置,所有的工作

<a ui-sref="static"> 
<a ui-sref="static.about"> 

检查它在行动here

的错误消息:

Error: Could not resolve 'static.about' from state 'static'

如果我们在状态定义(或调用方)中有一个错误,通常会发生。但这不是问题。或者,如果我们忽略加载定义文件...

相关问题