Maarten Heideman
Maarten Heideman

Reputation: 595

Ember route not found

i try to build an webapp with emberjs. this is the app router:

    App.Router.map(function() {
    this.route("page");
    this.route("menu");
    this.resource('posts', function(){
      this.resource('post', { path: '/:post_id' });
    });
    this.route("index", { path: "/" });
    this.route("cat");
    this.route("foto");
});

and this is the Postroute:

// GET POST JSON
App.PostRoute = Ember.Route.extend({
  model: function(params) {
    return Ember.$.getJSON('http://www.wilhelminaschool.eu/?json=get_post&post_id='+params.post_id);
  }
});

but i get an route not found error for the post, the posts list works. What i am doing wrong?

error: Error: Assertion Failed: The route post/11330 was not found

live on: http://www.wilhelminaschool.eu/app2/#posts http://www.wilhelminaschool.eu/app2/#post/11330

Upvotes: 0

Views: 3541

Answers (2)

melc
melc

Reputation: 11671

Each one of the posts links to app2/#post/:post_id i.e. app2/#post/11330 , but since the post resource has been defined within the resource of posts with a path of /:post_id the links should be app2/#/posts/:post_id i.e. app2/#/posts/11330

example,

http://emberjs.jsbin.com/budeyaja/1/edit

http://emberjs.jsbin.com/budeyaja/1 (please observe the urls while navigating)

If you need the links to work as they are then the routes will have to be specified as ,

this.resource("posts");
this.resource("post", {path:"/post/:post_id"});

http://emberjs.jsbin.com/qaquzusi/1/edit

Upvotes: 1

ppcano
ppcano

Reputation: 2861

Do not nest the post resource inside posts, use:

 this.resource('posts');
 this.resource('post', { path: '/post/:post_id' });

Ember Routing Guide provides a clear explanation of different cases.

Upvotes: 0

Related Questions