AngularJs UI 路由器

编程入门 行业动态 更新时间:2024-10-28 02:22:47
本文介绍了AngularJs UI 路由器 - 具有多个 URL 的一种状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我请求添加另一个 URL 参数,该参数指向我已设置的状态.出于效率目的,我试图查看是否可以添加多个 URL 以指向同一状态,或者我应该在这种新情况下使用 $UrlRouterProvider.when() 方法重定向到该状态.

例如.这是已经存在的

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

并且请求是添加指向link1页面的www.site/newlink.有没有这样的;

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

解决方案

尝试在 url 中使用正则表达式和参数.这不是最佳的,但有效.

.state('site.link1',{url: '/{path:link1|newlink}',templateUrl: '/views/link1.html',控制器:'link1Ctrl'})

更多信息网址中的正则表达式.

要生成带有ui-sref的链接,将状态名称作为函数传递相同的参数

<a ui-sref="site.link1({path:'link1'})" >站点链接 1</a><a ui-sref="site.link1({path:'newlink'})">站点新链接</a>

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/newlink that points to the link1 page. Is there something like this;

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

解决方案

Try using the Regex and a parameter in the url. It is not optimal but works.

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

More information on regex in Urls.

To generate links with ui-sref pass the same parameter with the state name as a function

<a ui-sref="site.link1({path:'link1'})" >site link 1</a>
<a ui-sref="site.link1({path:'newlink'})">site new link</a>

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

更多推荐

[db:关键词]

本文发布于:2023-04-22 00:13:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1012504.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   AngularJs   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!