angular-fullstack/generator-angular-fullstack

Logout does not properly redirect to previous page

Open

#1 717 ouverte le 17 mars 2016

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)JavaScript (1 268 forks)batch import
Help Wanted

Métriques du dépôt

Stars
 (6 134 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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)

Guide contributeur