title: AngularJS and SEO - 404 errors in Single Page Application
body: <p>I'm building a website using Express and AngularJS, but I'm fairly new to this technology and I'm coming from old plain PHP/HTML/JS. I understand the basics of this new approach, but I'm curious about the best practises for SEOs.</p>
  
  <p>Let's say I have a website built like this:</p>
  
  <ul>
  <li>A REST<em>ish</em> API to interact with that takes care about authentication, sessions and providing correct data</li>
  <li>A Single Page Application that is first loaded and provided statically which takes care of loading content using AngularJS</li>
  </ul>
  
  <p>Here's a draft:</p>
  
  <pre class="lang-none prettyprint-override"><code>- /api (dynamic content returns JSON)
    |
    + /login
    + /logout
    + /register
    + /music/:title
    + /music/:title/upvote
    + /user/:name
    + /user/:name/subscribe
    + /tag/:name
    + /search/:query
    + ...
  - / (everything is static here)
    |
    + index.html
    + /templates
      |
      + music.html
      + user.html
      + search.html
    + ...
  </code></pre>
  
  <p>Now whenever a user access a page the <code>index.html</code> is returned which then proceeds to "compose" itself with Angular.</p>
  
  <p>Therefore, if a resource isn't found either a <code>404 NOT FOUND</code> will be sent by the API (which uses JSONs) or AngularJS <code>.otherwise</code> will be called but how can a crawler understand it's a 404 (dead link) and drop the link if the first page returned when opening the URL is the index and the status code is 200?</p>
  
  <p>A manual solution could be to parse the URL when the index is first required, call the API to see if the resource is valid and throw an error if necessary, but in this scenario, if the resource requested is valid then there will be a double call to the API, and it's not good.</p>
  
  <p>What are the <em>state of art</em> best practises for handling this problem and other similar SEO-related?</p>
  
  <p>I've already read tons of articles about it, but they're all either deprecated or based on prerendering (which I'd like to avoid).</p>
  
  <p>Thank you very much for any help and advice you can give me.</p>