Routing, dynamic parameters, link-to


#1

I’m trying to get a route like this working:

Router.map(function() {
    this.route('due', { path: 'due-:when'});
});

And then link to like this:

{{#link-to 'due' 'past'}}Past Due{{/link-to}}
{{#link-to 'due' 'today'}}Due Today{{/link-to}}
{{#link-to 'due' 'tomorrow'}}Due Tomorrow{{/link-to}}

I feel like there is something fundamentally wrong in my understanding of how routing works, even after reading the docs and doing tutorials.

Could somebody please enlighten me?


#2

Have you tried the path ‘due/:when’?

You can’t have a dynamic segment without it actually being a different segment (’/’ delimited) of the URL. That should give you what you want.

See “dynamic segments” in the docs: http://emberjs.com/guides/routing/defining-your-routes/

If you are interested in seeing how the router parses dynamic segments: https://github.com/emberjs/ember.js/blob/v1.6.1/packages_es6/ember-routing/lib/vendor/route-recognizer.amd.js#L95


#3

Okay, that clears up one piece of the puzzle: dynamic “segments”. Got it. Thanks.


#4

I decided to go with this:

Router.map(function() {
  this.resource('tasks', {path: '/'}, function () {
    this.route('dashboard', {path: '/'});
    this.route('due');
    this.route('past-due');
    this.route('due-today');
    this.route('due-tomorrow');
    this.route('due-this-week');
    this.route('due-next-week');
    this.route('due-this-month');
  });
});

The number of urls is finite. That’s all my app will support. Adding more would be easy. It’s explicit. I can tell what urls are exposed just by looking at the router.

But now to figure out the next question.