0

I'm very new to Ember.js and I'm following this nettuts+ tutorial

I'm having an issue with routing in Ember.js.

I create my routes as follows:

App.Router.map( function() {

  this.resource( 'index', { path: '/' } ); 
  this.resource( 'gallery' ); 

});

And my template as follows:

<script type="text/x-handlebars" data-template-name="gallery">
  <h2>This is the gallery</h2>
</script>

And my links as follows:

<nav>
  {{#linkTo "index"}}Home{{/linkTo}}
  {{#linkTo "gallery"}}Gallery{{/linkTo}}
</nav>

When I want to access the "Gallery" path by clicking the link, it works fine and updates the url to: /ember-app/#/gallery but as per the Tutorial, the url path: /ember-app/gallery should render the proper template as well.

But, it doesnt and gives me a 404 error.

I'd really like to find out how to create a path without the /#/path and simply /path

Am I doing something wrong?

1 Answers1

1

You have to tell Ember that you want to use the history api.

App.Router.reopen({
  location: 'history'
});

http://emberjs.com/guides/routing/specifying-the-location-api/

Jeremy Green
  • 8,223
  • 1
  • 26
  • 31
  • 1
    Mind you that support for this depends on the user's browser supporting pushState. If you need to support more browsers refer to this: http://stackoverflow.com/questions/15056877/does-ember-routing-fall-back-to-using-a-hash-if-browser-doesnt-support-the-hist – digitalpixelpro Oct 20 '13 at 03:36
  • Another thing to consider that your server needs to be able to server any route for that app (e.g. is someone types `/ember-app/#/gallery` the server will serve `/ember-app/`, but if someone requests `/ember-app/gallery` you need your server to be able to respond to it as well – Miguel Madero Oct 21 '13 at 05:09