title: Redirect with Node.js and angular
body: <p>I am having trouble trying to redirect POST requests using Node.js, Express and angular. I am aware there is a standard way of using forms as follows:</p>
  
  <p><strong>index.ejs</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Redirect Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;INDEX PAGE&lt;/p&gt;
    &lt;form action="/redirect" method="post"&gt;
      &lt;button type="submit"&gt;CLICK&lt;/button&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>test.ejs</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Redirect Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;YAY REDIRECTED&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var fs = require('fs');
  var https = require('https');
  
  var express = require('express');
  var bodyParser = require('body-parser');
  var cookieParser = require('cookie-parser');
  
  var app = express();
  app.set('view engine', 'ejs');
  
  app.get('/', function(req, res) {
    res.render('index');
  });
  
  app.post('/redirect', function(req, res){
    res.redirect('/test');
  });
  
  app.get('/test', function(req, res) {
    res.render('test');
  });
  
  var port = process.env.PORT || 1337;
  app.listen(port, function(){
    console.log('http://localhost:' + port + '/');
  });
  </code></pre>
  
  <p>This method automatically redirects the page to the "test" route since it uses a form to handle the post request.</p>
  
  <p>However using when I use an angular approach, the page does not automatically redirect. How would I do this?</p>
  
  <p><strong>index.ejs</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html ng-app="project"&gt;
  &lt;head&gt;
    &lt;title&gt;Redirect Example&lt;/title&gt;
    &lt;script src="/javascripts/jquery/jquery.js"&gt;&lt;/script&gt;
    &lt;script src="/javascripts/angular/angular.js"&gt;&lt;/script&gt;
    &lt;script src="/javascripts/angular/angular-route.js"&gt;&lt;/script&gt;
    &lt;script src="/javascripts/main.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body ng-controller="MainController"&gt;
      &lt;button type="submit" ng-click="submit()"&gt;CLICK&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>var app = angular.module('project', []);
  app.controller('MainController', ['$scope', '$http', function ($scope, $http) {
  
    $scope.submit = function() {
      $http.post('/redirect');
    }
  }]);
  </code></pre>