登出后如何重定向用户

时间:2021-09-30 01:18:35

I have a front end built in Angular. I have the following code in app.js for when user clicks logout.

我有一个有棱角的前端。当用户单击logout时,我在app.js中有以下代码。

  .when('/logout', {
    templateUrl: 'mysite/views/logout.html',
    resolve: {
      authenticated: ['djangoAuth', function(djangoAuth){
        return djangoAuth.authenticationStatus();
      }],
    }
  })

logout.js contains

注销。js包含

'use strict';

angular.module('angularDjangoRegistrationAuthApp')
  .controller('LogoutCtrl', function ($scope, $location, djangoAuth) {
    djangoAuth.logout();
  });

logout.html simply contains this:

注销。html仅仅包含:

<div id="logout_view" ng-controller="LogoutCtrl">
    <div class="alert alert-info">You have logged out.</div>
</div>

All of this works fine, however, when user clicks /logout I don't want to show a the logout.html page which simply shows You have logged out rather I want to redirect the user to my main.html page. However, when I change the templateUrl to go to mysite/views/main.html then the LogoutCtrl isn't being called and the user isn't really being logged out.

但是,当用户单击/注销时,我不想显示一个注销。html页面,它只是显示您已经退出,而不是我想重定向用户到我的主。html页面。但是,当我更改templateUrl到mysite/views/main时。然后没有调用LogoutCtrl,用户也没有真正退出。

Question

问题

Is there a way I can redirect the user to main.html after he logs out successfully (meaning the logic in logout.js gets executed)

是否有办法将用户重定向到main。成功注销后的html(这意味着注销的逻辑)。js执行)

1 个解决方案

#1


3  

Just replace with following: (It will execute logout logic and will show your page)

只需替换如下内容:(它将执行注销逻辑并显示您的页面)

.when('/logout', {
    templateUrl: 'mysite/views/main.html',
    controller: LogoutCtrl,
    resolve: {
      authenticated: ['djangoAuth', function(djangoAuth){
        return djangoAuth.authenticationStatus();
      }],
    }
  })

#1


3  

Just replace with following: (It will execute logout logic and will show your page)

只需替换如下内容:(它将执行注销逻辑并显示您的页面)

.when('/logout', {
    templateUrl: 'mysite/views/main.html',
    controller: LogoutCtrl,
    resolve: {
      authenticated: ['djangoAuth', function(djangoAuth){
        return djangoAuth.authenticationStatus();
      }],
    }
  })