This must be a very stupid question because nobody else is asking it. I’m using Backbone.js with URLs for views like website.com/#article/12. To fetch the article, there is a GET request to /article/12. How do I redirect or 404 when the user goes to website.com/article/12 (without the hash) and sees the requested JSON in the browser?
Share
Your server should just respond to different HTTP requests in different ways based on the
Acceptheaders.On your server, if the request comes in with
Accept: application/jsonthen your app should return the JSON. Otherwise (like if it’sAccept: text/html) you can return the HTML view you want them to see, redirect, or whatever. How you do this would just depend on what language/framework you’re using, but should be relatively easy.Ideally you’d use the same URL for the client view and drop the
#tag (check out HTML5 pushState which Backbone.js supports nicely.)