3

Given this basic router definition for an Ember.js application taken straight from the Ember API docs here: http://emberjs.com/api/classes/Ember.Router.html

App = Ember.Application.create({
  Router: Ember.Router.extend({
    root: Ember.Route.extend({
      index: Ember.Route.extend({
        route: '/'
      }),
      ... additional Ember.Routes ...
    })
  })
});

This will produce the following url in chrome:

localhost/

but in Firefox and IE produces:

localhost/#

Not only does it add the hash bang at the end but the back button has history in Firefox and IE to:

localhost/

However this "state" is not able to be refreshed. Refreshing will again take you to:

localhost/#

This seems like the router is somehow pushing 2 states but one is not really valid. Can someone please explain what I am missing here?

sly7_7
  • 11,961
  • 3
  • 40
  • 54
gforce301
  • 2,944
  • 1
  • 19
  • 24

1 Answers1

2

By default Ember Apps have the # in the routes. I'm not sure why you're getting inconsistency, but in order to tell the router not to use # in the url you can set the "location" option:

App.Router = Ember.Router.extend({
  location: 'history'
});

Here is the place in the docs where it references the location attribute: http://emberjs.com/api/classes/Ember.Router.html#property_location

Andre Malan
  • 2,043
  • 12
  • 12
  • The # is not really my issue. I can live with it. My issue is that there is actual history in the browser to a url without the #, even though that is not a "re-loadable" state. Both Firefox and IE see 2 url's: / and /# – gforce301 Nov 13 '12 at 20:17
  • If you add the 'history' flag to the router does it fix the issue (or do you need there to be a "#")? My thought was that if you tell Ember not to use the # then it may only set one instead of both URLs. – Andre Malan Nov 14 '12 at 16:07
  • Setting the router to use the browser's history.pushstate API by setting location = "history", does indeed fix the issue but only in Firefox as IE does not support it. – gforce301 Nov 14 '12 at 23:07
  • This 'history' uses the HTML5 History feature which is not supported by IE before version 10. check http://caniuse.com/#feat=history. I have the same issue with the back button and so far we have no solution for FF and IE. Any idea since november ? – Sephy Aug 19 '13 at 16:06