Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 4 Ember Routing with History API
    text
    copied!<p>I have a problem trying to get the history API to work properly with ember in my rails app.</p> <p>This all <strong>works perfectly with the # URLs</strong>.</p> <p>In Rails I have a controller with an index action that renders my app. The whole page is the ember app, so it just loads the JS, stylesheets etc.</p> <p>I have two Rails routes...</p> <pre><code>root 'home#index' get 'posts', :to =&gt; 'home#index' </code></pre> <p>So I can render my rails app with either www.example.com OR www.example.com/posts</p> <p>In Ember I specify the history api in the router...</p> <pre><code>App.Router.reopen({ rootURL: '/', location: 'history' }); </code></pre> <p>I then have a single Ember route set-up...</p> <pre><code>Delib.Router.map(function() { this.resource('posts'); }); </code></pre> <p>I have templates for the Index and Posts routes.</p> <p>When I enter the root URL I get the Index template displayed.</p> <p><strong>When I enter the posts url e.g. /posts it still renders the Index template.</strong></p> <p>I added the logging info and it seems to recognize the posts route and then transition into the Index route, see below...</p> <pre><code>DEBUG: ------------------------------- ember.js?body=1:382 DEBUG: Ember.VERSION : 1.0.0-rc.8 ember.js?body=1:382 DEBUG: Handlebars.VERSION : 1.0.0 ember.js?body=1:382 DEBUG: jQuery.VERSION : 1.10.2 ember.js?body=1:382 DEBUG: ------------------------------- ember.js?body=1:382 generated -&gt; route:posts.index Object {fullName: "route:posts.index"} ember.js?body=1:382 generated -&gt; controller:application Object {fullName: "controller:application"} ember.js?body=1:382 Rendering application with default view &lt;(subclass of Ember.View):ember387&gt; Object {fullName: "view:application"} ember.js?body=1:382 generated -&gt; controller:index Object {fullName: "controller:index"} ember.js?body=1:382 Rendering index with default view &lt;Ember._MetamorphView:ember403&gt; Object {fullName: "view:index"} ember.js?body=1:382 Transitioned into 'index' </code></pre> <p>I get a single HTTP Request for this, so it <strong>definitely isn't a HTTP redirect</strong>.</p> <p>Interestingly, it has registered the move from /posts to / in the history API - so my <strong>back button is enabled</strong> and if I click back it correctly transitions to the /posts route and my posts Template is rendered. Again, this all works when I use the standard # URLs.</p> <p><em><strong>Anyone got any idea what I am doing wrong? Or is this somehow expected behaviour or is it an ember bug?</em></strong></p> <p>Thanks in advance! Post if you need more info.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload