CMS with Ember nice URL slugs and link to helper



I’m creating a small CMS with a Drupal backend ( for Ember. In the backend I have a field to define a path for each page. I’m having trouble how to architect the routing in a bice way. I would like to avoid using page ID and just use the path defined in the backend.

this is a property I can access through my api as one string /foo/bar/baz.

What I’m having trouble is defining my router so I can use the path defined in the api. It works when the slug is simply /foo or /bar. But what do I do if the slug is /foo/bar or just `/´ or any other length.

This is what my router looks like currently. {

       this.route('page', { path: '/:path });


I’m also having trouble with the menu. How can I define a LinkTo helper that would work for any url length. {{#link-to 'page' item.alias}} only works for urls in the first level.

Also I’m wondering how I would approach converting internal links that are used inside the body field with link-to helpers. I’m also having the same issue in the menu.


You might want to try using a wildcard route for this one.

this.route('page', { path: '/*path' });

Check out wildcard routing in the guides.

Here’s a twiddle showing how you can wire this up and grab the path in the route’s model hook:


I would like to avoid using page ID and just use the path defined in the backend.

You might break saved URLs if the path value changes. If you are using the same route/controller/template to load and display all the paths, you could do:

  this.route('pages', function () {
    this.route('show', { path: '/:page_id' });
    this.route('show', { path: '/:page_id/:path' });

Links can be generated with: {{#link-to "" pageId}} or {{#link-to "" pageId path}}.

This is similar to how Stackoverflow styles their URLs:<question-id>/<question-slug>.


The backend checks if a path has already been used for another page. So that should not be a problem. But maybe including the ID is safer.


The problem is what do I do if the path has several segments. /segment-one/segment-two Doesn’t the link to helper have to look different depending on the amount of segments? How can I anticipate that.