Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 如何在没有首先导航到index.html的情况下直接进入使用ui-router的状态大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用ui-router的AngularJS应用程序.一切正常,但我希望有一个用户注册确认屏幕,如下所示:

http://localhost:2757/Auth/confirmation

在我目前的配置中,当我打开带有此链接的浏览器页面时,它不会查找index.html,也不会进入/ Auth / confirm状态.我理解为什么会这样,但我不知道如何解决这个问题.

有人可以给我一些建议,告诉@R_489_11399@/如果我可以建立一个链接,让我直接进入/ 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中内置的功能中获益:

.when() for redirection

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

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

大佬总结

以上是大佬教程为你收集整理的angularjs – 如何在没有首先导航到index.html的情况下直接进入使用ui-router的状态全部内容,希望文章能够帮你解决angularjs – 如何在没有首先导航到index.html的情况下直接进入使用ui-router的状态所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。