I want to make a redirection to another route and the page have to be refreshed and treated server side, so the $location.path(url)
can't help me. I have tried window.location(url)
but I have this error: window.location is not a function
My app.js:
'use strict';
var app = angular.module('myApp', []).
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: 'partials/index'});
$routeProvider.when('/logout', {
controller: 'logoutCtrl'});
$routeProvider.otherwise({
redirectTo: '/'});
$locationProvider.html5Mode(true);
}]);
my logoutCtrl:
function logoutCtrl($scope, $location){
$apply(function() {
$location.path("/users/logout");
});
}
The partials/index contains this link:
a(href='/logout') Logout
Now I'm going to show how I manage my routes server side with Express.js:
app.get('/', ctrl.index);
app.get('/partials/:name', ctrl.partials);
app.get('/users/logout', ctrl.logout);
exports.logout = function(req, res)
{
console.log('logout');
req.session.destroy(function(err){ // I destroy my session
res.redirect('/'); // redirection to '/'
});
}
Now when I click on "logout" nothing happen, I'm just seeing this route localhost:3000/logout
in my bar but if I type localhost:3000/users/logout
I have the result expected (session destroyed and redirection to '/' )