angular-fullstack/generator-angular-fullstack

Logout does not properly redirect to previous page

Open

#1.717 aberto em 17 de mar. de 2016

Ver no GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (1.268 forks)batch import
Help Wanted

Métricas do repositório

Stars
 (6.134 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

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)

Guia do colaborador