Question

I'm trying to start to build a admin system that will run on a /admin/ prefix.

Here is my routes file

App.Router.reopen
  location: 'history'
  rootURL: '/admin'

App.IndexRoute = Ember.Route.extend
  setupController: (controller, model) ->
    @controllerFor('application').set('currentRoute', 'home')

When I go to /admin I get the following error:

Uncaught Error: No route matched the URL '/admin' 

I'm just starting with emberjs, and my code is based on this serie

Ember version: v1.0.0-pre.4
Ember-data current api revision:: 11
Was it helpful?

Solution 2

When talking about routing in emberjs, it depends which version you are using. There was a big API change between 1.0pre2 and 1.0pre3. The docu on www.emberjs.com is already up-to-date for the new API and and easy to understand.

Below a really small example that shows

  • IndexRoute that automatically redirects to the overview of all members at '/members'.
  • Dynamic routing based on an ID
  • Serialization/Deserialization in case that the parameter is not 'id' but something else. In the example below, it is 'refId' (stands for reference ID).

Well, the examle does not really show more than the official documentation. but add-on information is always nice.

So, hope this helps. cheers.

App.Router.map(function() {    
  this.resource("members", { path: '/members' });
  this.resource("member",  { path: "/members/:refId" }, function() {
    this.route("delete");
  });
});

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo('members');
  }
});

App.MembersRoute = Ember.Route.extend({
  model: function() {
    return App.Member.findAll();
  }
});

App.MemberRoute = Ember.Route.extend({
  model: function(params) {
    return App.Member.find(params.refId);
  },
  // overwrite default serializer (defaults to 'id', member has 'refId')
  serialize: function(model) {
    return { refId: model.refId };
  }
});

OTHER TIPS

In old-router the 'rootURL' property would have been ignored when resolving routes. In the latest version of ember, rootURL only seems to be used when constructing links. Not sure if this is a bug or oversight. As a workaround, try this instead:

App.Router.map(function() {    
  this.resource("admin",  { path: "/admin" }, function() {
    this.route("other");
  });
});

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo('admin');
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top