Search code examples
ember.jsember-router

Ember.js router with variable


I've just started using Ember.js and have got stuck at the first hurdle!

My URL structure is /username/action, so for example /matt/feed (or just /matt with a default view).

But, although I've managed to get a hardcoded username value to output something, I don't know how to have the username part of the URL be a variable which I can then do things with.

The code I'm using to hardcode the username is below, haven't really got anywhere because I'm not really sure how to get Ember.js to understand my URLs!

'use strict';
window.App = Ember.Application.create();
App.Router.reopen({
    location:'history'
});
App.Router.map(function() {
    this.resource('matt');
});

Solution

  • Right from the documentation at http://emberjs.com/guides/routing/defining-your-routes/#toc_dynamic-segments

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

    :post_id is the dynamic segment of the route.