我有一个使用UI路由器的AngularJS应用。所有的工作不错,但我想有这样的访问的用户注册确认屏幕:
的http://本地主机:2757 /认证/确认
在我的present配置,当我打开浏览器页面,此链接不去找index.html,然后不进入/认证/确认状态。我明白为什么会这样,但我不知道如何解决这个问题。
有人可以给我一些建议如何/如果我可以做一个链接,将让我到/认证/确认直接
所有我能想到的也许是这样的:
的http://本地主机:2757 / index.html的负荷= AuthConfirm
和然后以某种方式有检测到新的状态过渡检查一次中的index.html被装起来。
下面是我的AppConfig文件:
VAR AUTH = { 名称:'权威性', 网址:'/验证, 观点:{ '根': { templateUrl:应用程序/认证/谐音/ home.html做为 } }};VAR authContent = { 名称:'auth.content', 网址:'/:内容', 观点:{ '根': { templateUrl:应用程序/考试/谐音/ home.html做为 }, 内容:{ templateUrl:功能(stateParams){ 返回应用程序/认证/谐音/+ stateParams.content +'的.html' } } }}
这里的东西我想:
的http://本地主机:2757 / index.html的<<带我到我的主索引页
的http://本地主机:2757 / index.html的/验证<<返回页面没有找到
的http://本地主机:2757 / index.html的/认证/注册&LT ;<返回页面没有找到
解决方案我要说的是,我们所需要的就是 - 让 index.html的
被laoded - 作为一个SPA(单页应用程序)。然后,我们会从内置在UI的路由器功能中获益:
。当()
重定向
参数:
什么字符串|正则表达式| UrlMatcher要重定向进入的路径。结果 处理程序字符串|功能您希望将用户重定向到的路径。
处理程序
为String
如果处理程序是一个字符串,它是根据比赛的语法视为重定向,并进行插值(也就是喜欢与string.replace()的正则表达式,或者像UrlMatcher图案以其他方式)。
的app.config(函数($ urlRouterProvider){ //当有一个空的路线,重定向到/指数 $ urlRouterProvider.when('','/指数'); //你也可以使用正则表达式的匹配参数 $ urlRouterProvider.when(/ ASPX /我,'/指数');})
不然的话()
为无效的路由
参数:
路径字符串|功能要重定向到URL路径或返回URL路径的函数规则。功能版本传递两个参数:$喷油器和$位置
的app.config(函数($ urlRouterProvider){ //如果路径不匹配任何您配置的网址 //否则将用户路由到指定的URL的护理 $ urlRouterProvider.otherwise('/指数'); //使用功能治国参数的例子 $ urlRouterProvider.otherwise(函数($注射器,$位置){ ...一些先进的code ... });})
如何使用。当()
正常的(如为了声明)的内容请查看这里(更多细节和例子)的
I have an AngularJS application that is using ui-router. All is working okay but I would like to have a user registration confirmation screen accessed like this:
http://localhost:2757/Auth/confirmation
In my present configuration when I open a browser page with this link it does not look for the index.html and does not go to the /Auth/confirmation state. I understand why this happens but I do not know how to solve the problem.
Can someone give me some advice on how / if I can make a link that will get me to the /Auth/confirmation directly.
All I can think of is perhaps something like this:
http://localhost:2757/index.html?load=AuthConfirm
and then somehow have a check that detects a new state to transition to once the index.html is loaded up.
Here is my AppConfig file:
var auth = {
name: 'auth',
url: '/Auth',
views: {
'root': {
templateUrl: 'app/auth/partials/home.html'
}
}
};
var authContent = {
name: 'auth.content',
url: '/:content',
views: {
'root': {
templateUrl: 'app/exams/partials/home.html'
},
'content': {
templateUrl: function (stateParams) {
return 'app/auth/partials/' + stateParams.content + '.html'
}
}
}
}
Here's something I tried:
http://localhost:2757/index.html << takes me to my main index page
http://localhost:2757/index.html/Auth << returns page not found
http://localhost:2757/index.html/Auth/register << returns page not found
解决方案I would say that what we need here is - to let the index.html
be laoded - as a SPA (Single page application). Then we will profit from the features built in in the UI-Router:
.when()
for redirection
Parameters:
what String | RegExp | UrlMatcher The incoming path that you want to redirect. handler String | Function The path you want to redirect your user to.
handler
as String
If handler is a string, it is treated as a redirect, and is interpolated according to the syntax of match (i.e. like String.replace() for RegExp, or like a UrlMatcher pattern otherwise).
app.config(function($urlRouterProvider){
// when there is an empty route, redirect to /index
$urlRouterProvider.when('', '/index');
// You can also use regex for the match parameter
$urlRouterProvider.when(/aspx/i, '/index');
})
.otherwise()
for invalid routes
Parameters:
path String | Function The url path you want to redirect to or a function rule that returns the url path. The function version is passed two params: $injector and $location.
app.config(function($urlRouterProvider){
// if the path doesn't match any of the urls you configured
// otherwise will take care of routing the user to the specified url
$urlRouterProvider.otherwise('/index');
// Example of using function rule as param
$urlRouterProvider.otherwise(function($injector, $location){
... some advanced code...
});
})
How to use the .when()
properly (e.g. order of declaration) please check also here (with more details and examples)
相关推荐
最新文章