Angular UI-Router:单个状态的多个 URL [英] Angular UI-Router: Multiple URLs to single state

查看:35
本文介绍了Angular UI-Router:单个状态的多个 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用 angular 的 ui-router,我想弄清楚如何让多个 URL 引用一个状态.例如:

I have started using angular's ui-router, and I am trying to figure out how to have multiple URLS refer to a single state. For example:

/orgs/12354/overview
//retyrns the same pages as
/org/overview

我的 $state 提供者目前设置了这样的东西,我不清楚如何插入别名/org/overview"路由,以便它正确地从org"父级继承.

My $state provider is currently set with something like this, and its unclear to my how to slip in the alias '/org/overview' route such that it properly inherits from the 'org' parent.

.state('org', {
  abstract: true,
  url: '/orgs/:orgID',
  templateUrl: '/client/navigation/main.html'
})
.state('org.overview', {
  url: '/overview',
  templateUrl: '/client/overview/overview.html',
  controller: 'OverviewCtrl'

})

推荐答案

这可以使用 when() 来实现.假设这是您要使用多个网址指向的状态.

This can be achieved using when(). Suppose this is the state you want to point to with multiple urls.

.state('app.home',
  {
    url: '/home',
    templateUrl: 'home.html',
    controller: 'homeCtrl'
  })

config() 中你可以使用 when() 如下:

In config() you can use when() as follows:

angular.module('myApp', [])
   .config($urlRouterProvider){
       $urlRouterProvider.when(/homepage, ['$state','$match', function ($state, $match) {
          $state.go('app.home');
 }]);
}

同样,您可以添加多个指向同一状态的网址.

Likewise you can add multiple urls pointing to same state.

这篇关于Angular UI-Router:单个状态的多个 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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