问题描述
限时送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:关键词]
发布评论