Dynamic username route


#1

Hello,

I am new to Ember and looking at how I could convert my current app. One thing I haven’t figured out yet is how to create my user profiles. My current app uses the URL format: mydomain.com/username. In my current framework I first define which routes I want to use for all the static pages such as about, contact etc. I then send the remaining url’s to a handler that checks if username exists and creates a user profile page based on the username. Is this even possible with ember? On each profile I would then have the route /username/photo/12 /username/followers etc.

Thanks, Michael


linkTo helper basics
#2

Of course. You’d have to show us more of your URL schema for us to be specific, but as per your example:

App.Router.map(function() {
  this.route('about');
  this.route('faq');
  //etc
  this.resource('user', { path: '/:username' }, function({
    this.resource('photo', { path: '/photo/:photo_id'});
    this.route('followers');
  });
});

If you’re going have usernames as the first parameter after you’re domain, you’ll have to make sure no usernames match your static page names. The router will stop ‘routing’ after it finds the first match. So for example if you had a user called ‘about’, they wouldn’t be matched in the above example.

You should checkout the official Ember guides on the router, I’ve found them very helpful.


#3

Thanks for your reply! With your example code it looks so easy and obvious :smile: Now I can get started with my app.


#4