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

查看:24
本文介绍了使用 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-view,但这似乎是不可能的.

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. 导航到与状态关联的网址.

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

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

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