angular-fullstack/generator-angular-fullstack

Logout does not properly redirect to previous page

Open

#1717 aperta il 17 mar 2016

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)JavaScript (1268 fork)batch import
Help Wanted

Metriche repository

Star
 (6134 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Using ngroute, In client/app/account/account.js

controller: function($location, $route, Auth) {
          var referrer = $route.current.params.referrer ||
                          $route.current.referrer ||
                          '/';
          Auth.logout();
          $location.path(referrer);
        }

and

  .run(function($rootScope) {
    $rootScope.$on('$routeChangeStart', function(event, next, current) {
      if (next.name === 'logout' && current && current.originalPath && !current.authenticate) {
        next.referrer = current.originalPath;
      }
    });

Logout does not work properly when the previous page has a parameter in the url (such as /courses/000000000000000000000010 where the route is /courses/:id. Instead of returning to the url /courses/000000000000000000000010, it returns to /courses/:id ).

This is using the route provider:

    $routeProvider
      .when('/courses/:id', {
        templateUrl: 'app/courses/view/courseview.html',
        controller: 'CourseViewCtrl'
      });

Instead, using the following works for me (although there may be intricacies with $window.location.pathname that are not showing up in my app.)

  .run(function($rootScope, $window) {
    $rootScope.$on('$routeChangeStart', function(event, next, current) {
      if (next.name === 'logout') {
        next.referrer = $window.location.pathname;
      }
    });
  });

Using $window.history.back(); instead of $location.path(referrer); also seems to work fine. using location.path() instead of $window.location.pathname does not work. (instead just returning /logout)

Guida contributor