angularjs – 如何在没有首先导航到index.html的情况下直接进入
我有一个使用ui-router的AngularJS应用程序.一切正常,但我希望有一个用户注册确认屏幕,如下所示:
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<<返回页面未找到 解决方法
我想说我们需要的是 – 让index.html成为一个SPA(单页面应用程序).然后我们将从UI-Router中内置的功能中获益:
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'); })
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* (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |