Ad

AngularJS Redirect After Login

- 1 answer

its me... again... Well, i need to put a redirect with AngularJS on my controller when the login are sussesufull. I have read a loooooot and i find this. The example is clear using ui-router, very easy. I put on my index.html all the code "base" of my app, and i put a 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. The idea are: all the content of login.html appears on this <div> ui-view></div> is correct?

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:

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. The homepage is http://192.168.0.203/solempmobile. Is something that im doing wrong?

[UPDATE 1]

So i have looking around the code and finally it works... buuuut..... not at the expected way. The route works... but the ccs related to jquery mobile does not. I have to put off this:

    <div data-role="page">

outside the partial view, but the page are so ugly...

Ad

Answer

You can simply redirect using HTML! so first make a simple HTML FIle call it 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:

<html>
  <herects... Idk if this is the right url, but you can change it:

<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!

Ad
source: stackoverflow.com
Ad