Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
 
You may try $location.url('/logout') –  zsong Aug 20 at 19:26
 
That's the first thing I tried. Doesn't work in or out of html5mode –  Drew H Aug 20 at 19:35
 
Well, I think you may detect the browser to see whether it supports the pushState or not. If not then add the #! manually. :) –  zsong Aug 20 at 20:03
 
The logout url is a traditional url that needs to hit the server. In this case this is not working. All the client side routing is working, in html5mode and in older browsers. Thanks –  Drew H Aug 20 at 20:20
2  
Have you tried linking like so: <a href="/logout" target="_self">Logout</a>? –  bibs Aug 21 at 2:15
show 3 more comments

1 Answer

up vote 1 down vote accepted

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: http://docs.angularjs.org/guide/dev_guide.services.$location (search for _self).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.