Narutocc / angular

:hear_no_evil:AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop.
1 stars 0 forks source link

angular-ui-router API #12

Open Narutocc opened 6 years ago

Narutocc commented 6 years ago

UI Router 中有三种方式激活一个路由: (1)$state.go():优先级较高的便利方式 (2)ui-sref:点击包含此指令跳转 (3)url:url导航

一、$state.go()

(1)$state.go(to[,toParams][,options]) 参数: to:绝对“state名称”或者相对的"state路径"(如果路径,以“^或者.”是相对,否则为绝对) toParams:发送给state的数据参数,由$stateParams构建 options:{ location: true, inherit: true, relative: $state.$current, notify: true} (2)$state.transitionTo(to,toParams[,options]) $state.go()内部调用此方法 (3)$state.reload()

二、ui-sref

此指令必须绑定到标签,如果该路由有对应的关联URL,其通过$state.href()自动生成和更新href属性。

<a ui-sref="home">home</a>

(1)ui-sref-active="active" 该路由激活,则对应增加active样式名称

<ul>
    <li ui-sref-active="active" class="item">
        <a href ui-sref="app.user({user:'test'})">@test</a>
    </li>
</ul>

当路由是“app.user”,且包含参数user值为test,会变成如下:

<ul>
    <li ui-sref-active="active" class="item active">
        <a ui-sref="app.user({user:'test'})" href="/user/test">@test</a>
    </li>
</ul>

(2)ui-sref-opts传递参数

<a ui-sref="home" ui-sref-opts="{reload:true}">Home</a>

三、URL Routing

$stateProvider.state("nav",{
        url:"...",
        templateUrl:"..."
})

其支持正则、查询参数 (1)$urlRouterProvider.when() (2)$uelRouterProvider.otherwise() (3)$urlRouterProvider.rule()