简体   繁体   English

登录后AngularJS重定向

[英]AngularJS redirect after login

its me... again... Well, i need to put a redirect with AngularJS on my controller when the login are sussesufull. 它是我...再次...好吧,当登录名被挂起时,我需要在控制器上放置AngularJS重定向。 I have read a loooooot and i find this . 我读了一遍,发现了这个 The example is clear using ui-router, very easy. 使用ui-router可以清楚地看到该示例,非常简单。 I put on my index.html all the code "base" of my app, and i put a div: 我在我的应用程序的所有代码“ base”上都放了index.html,然后放了一个div:

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

And the rest of my first page are on login.htm. 我的第一页的其余部分位于login.htm上。 The idea are: all the content of login.html appears on this <div> ui-view></div> is correct? 想法是:login.html出现在此<div> ui-view></div>内容正确吗?

Then there is my config on my app: 然后在我的应用程序上有我的配置:

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

The problem is when i put the url on my web browser: 问题是当我将URL放在Web浏览器上时:

http://192.168.0.203/solempmobile

returns: 收益:

http://192.168.0.203/solempmobile/#/solempmobile

And all are in a empty page. 所有都在一个空白页中。 The web server are IIS, and the app are on a virtual directory. Web服务器是IIS,应用程序在虚拟目录上。 The homepage is http://192.168.0.203/solempmobile . 主页是http://192.168.0.203/solempmobile Is something that im doing wrong? 我做错了什么吗?

[UPDATE 1] [更新1]

So i have looking around the code and finally it works... buuuut..... not at the expected way. 所以我查看了一下代码,终于可以了... buuuut .....不是按预期的方式。 The route works... but the ccs related to jquery mobile does not. 该路由有效...但是与jquery mobile相关的ccs无效。 I have to put off this: 我不得不推迟:

    <div data-role="page">

outside the partial view, but the page are so ugly... 部分视图之外,但是页面太丑了...

You can simply redirect using HTML! 您可以简单地使用HTML进行重定向! so first make a simple HTML FIle call it index.html... 因此,首先创建一个简单的HTML文件,将其命名为index.html ...

Then make a state where it is in the home page "/" like this: 然后将其置于主页“ /”中,如下所示:

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

Then in your index.html: You can have a meta tag which automatically redirects... Idk if this is the right url, but you can change it: 然后在您的index.html中:您可以具有一个自动重定向的meta标记...如果这是正确的url,则为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>

Hope this helped! 希望这对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM