Location history feature and unbookmarkable route URLs

Hi all,

With the location: ‘history’ option, it seems we have two limitations:

  1. We have to specify the ‘rootURL’ in router as the hardcoded context path of the app - there may be alternatives like finding the URL fragment from window.location.href to find the context path or if you use JSP, find pageContext.contextPath, but why is this needed by this feature in first place or is there an alternative? Otherwise, it does not seem to recognise the index route of the app itself.

  2. Every other route other than the index router taken by the app when using this location: ‘history’ option, results in a URL like http://host:port/app_name/route where this URL appears in browser, but this URL on refresh results in a 404. So if this URL is accidentally bookmarked by end user, it may later show a 404. Am I missing something here, for all these tests, (I use RC 1 in my local dev box)? But I have a sample here that is supposedly built with ember RC 3.

Looking for some pointers/guidance from the forum members,

Thanks, Paddy

You need to have your server set up in a way that responds to every request by serving up your app.

For example, in Rails you can add a catch-all route to routes.rb:

get '*ember' => 'static#app'

Hi,
I don’t know if I am missing something, but can’t we have a standalone simple web app without a Rails backend? I have one such fully standalone web app, that does not have a direct backing Rails server, but instead has modular REST services providing data for the UI (Ember does not come into the picture of those REST endpoints at all) So how do I have a catch all route for such a scenario?

Thanks,
Paddy

Not sure if you are using Apache for a webserver but here is a similar question on SO that describes modifying the .htaccess file.

You don’t need to be using a rails backend, but your server side wether it be a framework like rails, or a simple apache server has to be setup so any route to your app serves up the same content.

This post has an example Apache rewrite rule that would redirect all routes to an index.html file.

*edit I kept tyring to post a link to a similar question on the forums, but the link doesn’t work right. Someone else posted a similar link so I’m removing it :slight_smile:

Thank you all for the information on URL rewrites. I tried UrlRewriteFilter but can any of you let me know how to write rules for my Ember app? If I just have the one rule to redirect all “/*” requests to “%{context-path}%”, it does not work and seems to append lot of unnecessary characters. Any pointers will be of great help.

Thanks,
Paddy

Wouldn’t that catch-all route invalidate 404 pages?

On the server, yes, but as you are running a client-side app you would be handling 404’s in Ember instead.

There’s an example here using a wildcard route for a “404” type page. You can also redirect to a 404 if a model fails to load.

http://jsbin.com/ucanam/155/edit

Smart. Is Ember smart enough to match the last route after it has exhausted all other options? Otherwise that catch-all, would catch all.