AngularJS登录后重定向

AngularJS redirect after login

本文关键字:重定向 登录 AngularJS      更新时间:2023-09-26

是我...再。。。好吧,当登录完成时,我需要在我的控制器上使用 AngularJS 进行重定向。我读过一篇论文,我找到了这个。使用ui路由器的例子很清楚,非常简单。我把我的索引放上.html我应用程序的所有代码"基础",我放了一个div:

<body ng-app="solempApp">
    <!-- Start of first page -->
    <div ui-view></div>
</body>

我第一页的其余部分都在登录.htm。这个想法是:登录的所有内容.html出现在这个<div> ui-view></div>上是否正确?

然后是我的应用程序上的配置:

angular
.module('solempApp',['ngMessages', 'angular-loading-bar','ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/solempmobile');
    $stateProvider
    // HOME STATES AND NESTED VIEWS ========================================
    .state('solempmobile', {
        url: '/solempmobile',
        templateUrl: 'login.html'
    }) 
    // ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
    .state('about', {
        // we'll get to this in a bit       
    });   
})

问题是当我将 url 放在我的网络浏览器上时:

http://192.168.0.203/solempmobile

返回:

http://192.168.0.203/solempmobile/#/solempmobile

所有这些都在一个空白的页面中。Web 服务器是 IIS,应用位于虚拟目录中。主页是 http://192.168.0.203/solempmobile。是我做错了什么吗?

[更新1]

所以我环顾了一下代码,终于可以工作了......布乌特.....不是以预期的方式。路线有效...但与jQuery Mobile相关的CCS没有。我必须推迟这个:

    <div data-role="page">

在部分视图之外,但页面太丑了...

你可以简单地使用 HTML 重定向!所以首先做一个简单的 HTML FIle 称之为索引.html...

然后在主页"/"中的位置创建一个状态,如下所示:

.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/solempmobile');
    $stateProvider
    // HOME STATES AND NESTED VIEWS ========================================
    .state('Home', {
        url: '/'
        templateUrl: 'index.html'
        })
    .state('solempmobile', {
        url: '/solempmobile',
        templateUrl: 'login.html'
    }) 
    // ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
    .state('about', {
        // we'll get to this in a bit       
    });   
})

然后在您的索引中.html:您可以有一个自动重定向的元标记...如果这是正确的网址,则为 Idk,但您可以更改它:

<html>
  <head>
    <META http-equiv="refresh" content="5;URL=http://192.168.0.203/solempmobile/#solempmobile/solempmobile">
<!-- Type in whatever HTTPS you want to go to. In your case your login page... -->
  </head>

  </body>
</html>

希望这有帮助!