Search code examples
javascriptember.jscoffeescriptember-router

Setting the Ember root URL without redirection


Let's say my Router looks like this:

Bananas.Router.map ->
  @resource "bananas", ->
    @route 'index', path: '/'

and my BananasIndexRoute looks like this:

Bananas.BananasIndexRoute = Ember.Route.extend
  setupController: (controller) -> 
    controller.set("content", [ "baby", "manzano", "burro", "plantain", "red" ])

Manipulating the bananas belongs in the BananaController, but when the user visits waytomanybananas.com, I'd like they to be able to interact with my application. Currently, I'm accomplishing this by redirecting the user to the bananas path like this:

Bananas.IndexRoute = Ember.Route.extend
  redirect: -> @transitionTo("bananas")

However, I'd prefer to have the the application render the bananas route when I visit the root URL (the equivilent of root in Rails). What's the best way to accomplish this using Ember?


Solution

  • Add a path to your resource:

    Bananas.Router.map ->
        @resource 'bananas', { path: '/' }, ->