Optional dynamic segments

I have a requirement for the following route setup:

  • /user/:user_id/feed - displays today’s feed items
  • /user/:user_id/feed/:date - displays the selected date’s feed items

The second route doesn’t need it’s own controllers, views or templates, all it needs to do is change a property on the first route’s controller.

I’ve tried using multiple dynamic segments in the route but that seems to require that all the segments are passed, even when using route globbing.

How can I have a route with an optional segment at the end or should I be handling this in a completely different way?

1 Like

Either wait for the query string implementation to make it into the code http://discuss.emberjs.com/t/query-string-support-in-ember-router/1962/44 or you have to explicitly specify each and every route/controller etc.

We should make a patch for this; It’s such an important feature, but logically the underlying implications on the router are huge…

This has a lot of good use cases. /t/:slug/:id(/:nearPost) even. I was curious so I looked into what discourse is doing:

Discourse.TopicFromParamsNearRoute = Discourse.TopicFromParamsRoute;
3 Likes

Query parameters are now available in canary build Query Parameters - Routing - Ember Guides

Is this at all possible? I’m used to the /segment(/:possibleVar) type routes. Would love if there were a way to do this. Haven’t seen anything in docs yet about this.

1 Like