登录后{AnglerJS重定向

时间:2016-01-24 01:39:14

标签: javascript html angularjs

再次......我... 好吧,我需要在我的控制器上使用AngularJS进行重定向,当登录是susessefull时。我读了一个loooooot,我发现this。使用ui-router很清楚这个例子很简单。 我在index.html上添加了所有代码" base"我的应用程序,我把一个div:

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

我的第一页的其余部分都在login.htm上。我的想法是:此<div> ui-view></div>上显示的login.html的所有内容是否正确?

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

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       
    });   
})

问题是当我把网址放在网页浏览器上时:

http://192.168.0.203/solempmobile

返回:

http://192.168.0.203/solempmobile/#/solempmobile

所有人都在空白页面。 Web服务器是IIS,应用程序位于虚拟目录中。主页为http://192.168.0.203/solempmobile。 是不是我做错了什么?

[更新1]

所以我一直在寻找代码,最后它的工作原理...... buuuut .....不是按照预期的方式。路由有效......但与jquery mobile相关的ccs却没有。 我不得不推迟这个:

    <div data-role="page">

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

1 个答案:

答案 0 :(得分:1)

您只需使用HTML重定向即可!所以首先制作一个简单的HTML文件,将其称为index.html ...

然后在主页中显示一个状态&#34; /&#34;像这样:

.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       
    });   
})

然后在你的index.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>

希望这有帮助!