Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logout url in html5mode angularjs?

So right now I have configured html5mode.

    $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix('!');

This is end of my middelware for express to support html5mode

app.use(function (req, res) {
    if (!req.path.match('/calendar|/user|/create|/profile')) {
        return res.send(404);
    }
    res.render('home/index', {
        currentUser: req.user
    });
});

And all my urls are working good in Chrome and Firefox 3.6(which I'm using to test hashbang fallback).

My only issue is with the logout route. My logout is a server interaction. So I did this.

    $rootScope.logout = function () {
        window.location = '/logout';
    };

And made an ng-click to this function and that worked for logging out in Chrome. How would I go about doing this in the hashbang fallback mode? It's not working in Firefox 3.6. Thanks!

like image 820
Drew H Avatar asked Aug 20 '13 19:08

Drew H


1 Answers

Add a target="_self" to the link like this:

<a href="/logout" target="_self">Logout</a>

AngularJS ignore links with a target attribute. This is documented here: HTML link rewriting (search for _self).

like image 95
Maxence Avatar answered Oct 21 '22 14:10

Maxence