Skip to content

Logout does not properly redirect to previous page #1717

Open
@kmcnellis

Description

@kmcnellis

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions