Tom Pinchen
Tom Pinchen

Reputation: 2497

Page error on page refresh Ember app

I have an ember app that I am developing and everything is working fine except when I refresh the page whilst on a nested route eg. /projects/1 I receive the following error:

Assertion Failed: You may not passundefinedas id to the store's find method

I am fairly sure this is to do with the way I have setup my routing but can't seem to reorganise them to fix it.

They look like so:

App.Router.reopen({
  location: 'auto',
  rootURL: '/'
});

App.Router.map(function() {
  this.route('projects', { path: '/'});
  this.route('project', { path: '/projects/:id' });
});

Any help would be awesome! Thanks.

Upvotes: 0

Views: 159

Answers (1)

Daniel
Daniel

Reputation: 18672

My first suggestion for you would be to change :id segment do :project_id - it's how they define it in documentation. So your router code looks like:

App.Router.map(function() {
  this.route('projects', { path: '/'});
  this.route('project', { path: '/projects/:project_id' });
});

If this doesn't help, create:

App.ProjectRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.find('project', params.project_id);
  },
});

If you still get error with passing undefined to store.find try to console.log(params) and see if project_id is defined there and matches value from URL.

Upvotes: 1

Related Questions