AngularJs UI路由器 - 一个国家有多个网址 [英] AngularJs UI router - one state with multiple URLs

查看:124
本文介绍了AngularJs UI路由器 - 一个国家有多个网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在引导到我已经建立了一个国家的另一个URL参数添加请求。为了提高效率的目的,我想看看我是否可以添加多个网址指向相同的状态,或者我应该只使用$ UrlRouterProvider.when()方法来重新定向到这一新的情况下的状态。

防爆。这是已经存在

  .STATE('site.link1',
  {
    网址:'/ LINK1',
    templateUrl:/views/link1.html',
    控制器:'link1Ctrl
  })

和该请求是要添加www.site.com/newlink指向LINK1页面。有没有这样的东西;

  .STATE('site.link1',
  {
    网址:'/链接1,/ NEWLINK',
    ...


解决方案

您使用PARAMS:

https://github.com/angular-ui/ui-路由器/维基/ URL路由

  .STATE('site.link',
{
    网址:'/的{link}
    ..
}

所以,当你使用相同的状态,像这样

  $ state.go('site.link',{链接:链接1'})
$ state.go('site.link',{链接:链接2'})

I have a request to add in another URL parameter that directs to a state that I already have set up. For efficiency purposes, I'm trying to see if I can add multiple URLs to point to the same state, or should I just use the $UrlRouterProvider.when() method to re-direct to that state in this new case.

Ex. this is what already exists

.state('site.link1',
  {
    url: '/link1',
    templateUrl: '/views/link1.html',
    controller: 'link1Ctrl'
  })

and the request is to add www.site.com/newlink that points to the link1 page. Is there something like this;

.state('site.link1',
  {
    url: '/link1, /newlink',
    ...

解决方案

You use params:

https://github.com/angular-ui/ui-router/wiki/URL-Routing

.state('site.link',
{
    url: '/{link}'
    ..
}

so when you use the same state like this

$state.go('site.link', {link: 'link1'})
$state.go('site.link', {link: 'link2'})

这篇关于AngularJs UI路由器 - 一个国家有多个网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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