Optional segments in router

I’m currently having an issue where I want to have 2 different instances of a resource map to the same routes, controllers, templates, etc, where the resource contains an optional segment. As of right now, query parameters is not an option. We are using Rails on top of our Ember application. It would take some major refactoring to support query params, and it seems as though this functionality should exist in Ember. Also, I’ve looked at all the topics similar to this here, checked issues, PRs, etc. on GitHub, looked at StackOverflow, but to no avail.

Here is an example of the URLs I want to be caught by the router


As you can see, I want some :locale abbreviation that can be optional.

@resource 'guests.reservation', path: '/{{_want_optional_locale_segment_}}/reservations/:id'

Is this possible in any version of Ember, other than some brute force ugly way? Let me know if you need more details.

Thanks, and I appreciate you taking a look!

I got it to work using a wildcard route/resource and duplicated the routes within there. The Ember Inspector doesn’t show all the routes but it does work. And if you use a resource (at least for the “root” route, eg: reservations) it’ll still use the same controller, template, etc. Unfortunately I’m not sure if/how you can just tell the wildcard route to just alias all other routes, rather than listing them a second time.


Sweet thanks for the reply. Makes sense, trying this out. Is there any information floating around about supporting this more cleanly in the future?

I don’t know of any. In fact, I think .resource() might be going away in the future with the introduction of nestable .route()'s. Might be beneficial to pose this use case on the ember irc channel. Plenty of knowledgeable folks there who might have a better option anyway.