http://localhost:2757/Auth/confirmation
在我目前的配置中,当我打开带有此链接的浏览器页面时,它不会查找index.html,也不会进入/ Auth / confirm状态.我理解为什么会这样,但我不知道如何解决这个问题.
有人可以给我一些建议,告诉我如何/如果我可以建立一个链接,让我直接进入/ Auth /确认.
我能想到的可能是这样的:
http://localhost:2757/index.html?load=AuthConfirm
然后以某种方式检查一下,在index.html加载后检测到要转换到的新状态.
这是我的AppConfig文件:
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' } } } }
这是我尝试过的东西:
http://localhost:2757/index.html<<带我到我的主索引页面 http://localhost:2757/index.html/Auth<<返回页面未找到 http://localhost:2757/index.html/Auth/register<<返回页面未找到
解决方法
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 StringIf 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... }); })
如何正确使用.when()(例如声明的顺序)请在这里查看(更多细节和示例)
> Angular UI-Router $urlRouterProvider .when not working *anymore*
> Angular UI-Router $urlRouterProvider .when not working when I click