admin管理员组

文章数量:1389772

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!

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 asked Aug 20, 2013 at 19:07 Drew HDrew H 4,7399 gold badges59 silver badges92 bronze badges 8
  • You may try $location.url('/logout') – zs2020 Commented Aug 20, 2013 at 19:26
  • That's the first thing I tried. Doesn't work in or out of html5mode – Drew H Commented Aug 20, 2013 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. :) – zs2020 Commented Aug 20, 2013 at 20:03
  • 1 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 Commented Aug 20, 2013 at 20:20
  • 2 Have you tried linking like so: <a href="/logout" target="_self">Logout</a>? – bibs Commented Aug 21, 2013 at 2:15
 |  Show 3 more ments

1 Answer 1

Reset to default 11

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).

本文标签: javascriptLogout url in html5mode angularjsStack Overflow