Ember Router rootURL parameter (error if missing: route does not match url / admin)

I am trying to create an admin system that will run on the / 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 am just getting started with emberjs and my code is based on this series

Ember version: v1.0.0-pre.4
Ember-data current api revision:: 11

      

+3


source to share


2 answers


Talking about routing in emberjs it depends on which version you are using. There was a big API change between 1.0pre2 and 1.0pre3. The document at www.emberjs.com has already been updated for the new API and is clear.

Below is a very small example showing

  • IndexRoute, which automatically redirects all members to the general overview in '/ members'.
  • Dynamic routing based on ID
  • Serialization / deserialization in case the parameter is not an identifier, but something else. In the example below, this is "refId" (meaning reference id).


Well, actually this exam doesn't show any more official documentation. but the information about the add-on is always nice.

So, hope this helps. amuses.

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 };
  }
});

      

+1


source


In the old router, the rootURL property would be ignored when resolving routes. In the latest version of ember, the rootURL is only used when creating links. Not sure if this is a bug or an 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');
  }
});

      

+3


source







All Articles