title: Routing in Symfony2 with AngularJS
body: <p>I have Symfony2 for REST api and AngularJS on the front-end. Can't figure out how to deal with the routing. I have the following setup, that doesn't work:</p>
  
  <p>In the Symfony2 controller:</p>
  
  <pre><code>/**
   * @Route("/", name="index")
   * @Route("/post/{slug}", name="post")
   * @Template()
   */
  public function indexAction()
  {
      // index.html.twig is a plain html file with inclusion of all the scripts
      return $this-&gt;render('AcmeAppBundle::index.html.twig');
  }
  </code></pre>
  
  <p>Angular setup:</p>
  
  <pre><code>angular.module('acmeApp', [])
      .config(['$routeProvider',
          function($routeProvider) {
              $routeProvider
                  .when('/', {
                      templateUrl: '/assets/partials/index.html',
                      controller: "MainCtrl"
                  })
                  .when('/post/:slug', {
                      templateUrl: '/assets/partials/post.html',
                      controller: "PostCtrl"
                  })
                  .otherwise({
                      redirectTo: '/'
                  });
          }
      ])
      .config(['$locationProvider',
          function($locationProvider) {
              $locationProvider.html5Mode(true).hashPrefix('!');
          }
      ])
  </code></pre>
  
  <p>When I open <code>acme.com/</code> and follow a link to <code>acme.com/post/123</code>, this works fine, Angular picks up the route. But when I start from <code>acme.com/post/123</code>, Symfony2 redirect to <code>acme.com/post</code>and I'm not getting to the post page.</p>
  
  <p>Any recommendation how you setup routing in Symfony2 to use with Angular JS?</p>
  
  <p><strong>Update:</strong>
  Adding <code>&lt;base href="/"&gt;</code> to <code>index.html.twig</code> seems to fix the problem.</p>