Mick F
Mick F

Reputation: 7439

Why is my ember routing not used?

I'm starting developing with Ember using ember-rails with Rails 4.1.

With the following routes defined:

MyApp.Router.reopen({
    rootURL: '/mycontroller/'
})
MyApp.Router.map () ->
    this.route('welcome')

When I access the URL http://mysite/mycontroller/welcome, the welcome template is not rendered but the index one is.

DEBUG: -------------------------------
DEBUG: Ember      : 1.8.0 
DEBUG: Ember Data : 1.0.0-beta.11 
DEBUG: Handlebars : 1.3.0 
DEBUG: jQuery     : 1.11.1 
DEBUG: ------------------------------- 
Attempting URL transition to / 
generated -> route:application Object {fullName: "route:application"} ember.js?   body=1:15359
generated -> route:index Object {fullName: "route:index"} 
Transition #0: application: calling beforeModel hook 
Transition #0: application: calling deserialize hook 
Transition #0: application: calling afterModel hook 
Transition #0: index: calling beforeModel hook 
Transition #0: index: calling deserialize hook 
Transition #0: index: calling afterModel hook 
Transition #0: Resolved all models on destination route; finalizing transition. 
generated -> controller:application Object {fullName: "controller:application"} 
Could not find "application" template or view. Nothing will be rendered Object {fullName: "template:application"} 
generated -> controller:index Object {fullName: "controller:index"} 
Rendering index with default view <(subclass of Ember.View):ember307> Object {fullName: "view:index"} 
Transitioned into 'index' 
Transition #0: TRANSITION COMPLETE. 

How come my route is not understood?

Upvotes: 1

Views: 122

Answers (1)

AJ Gregory
AJ Gregory

Reputation: 1609

By default, Ember routing expects a hash symbol in your URL before the route. To navigate to your welcome route the URL should be http://mysite/mycontroller/#/welcome.

If you don't like this behavior it can be disabled by having Ember interact with a browser's history API like so:

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

You could then use the URL http://mysite/mycontroller/welcome as expected.

Here are the docs on Ember URL types

Upvotes: 1

Related Questions