使用ui-router将父状态默认为子状态 [英] Have parent state default to child state using ui-router

查看:57
本文介绍了使用ui-router将父状态默认为子状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个状态结构:

.state('places',
{
    url:'/places',
    controller:'PlacesController',
    templateUrl:'views/places.html'
})
.state('places.city',
{
    url:'/:city',
    templateUrl:function(stateParams)
    {
        return 'views/places/'+stateParams.city+'.html';
    }
});

除了URL只是/places后没有城市时,它工作得很好.
在子状态下,如何为templateUrl设置默认值?

It works nicely except when the URL is simply /places without a city after it.
How can I have a default value for templateUrl in the child state?

我在想最好的方法是从PlacesController设置ui视图,但这似乎是不可能的.

I'm thinking the best way would be to set the ui-view from PlacesController, however that doesn't seem to be possible.

推荐答案

如Angular-UI Wiki页面中所述:

As stated in the Angular-UI Wiki page:

有三种主要的激活状态的方法:

There are three main ways to activate a state:

  1. 调用$ state.go().高级便利方法.
  2. 单击包含ui-sref指令的链接.
  3. 导航到与状态关联的网址.
  1. Call $state.go(). High-level convenience method.
  2. Click a link containing the ui-sref directive.
  3. Navigate to the url associated with the state.

https://github.com/angular-ui/ui-router/wiki#activating-a-state

这篇关于使用ui-router将父状态默认为子状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆