Skip to content

Instantly share code, notes, and snippets.

@xhh
Created August 4, 2012 00:59
Show Gist options
  • Save xhh/3253196 to your computer and use it in GitHub Desktop.
Save xhh/3253196 to your computer and use it in GitHub Desktop.
ember.js routing problem
window.App = Ember.Application.create
rootElement: '#container'
ApplicationController: Ember.ObjectController.extend()
ApplicationView: Ember.View.extend
templateName: 'application'
Router: Ember.Router.extend
root: Ember.Route.extend
home: Ember.Route.extend
route: "/"
connectOutlets: (router) ->
console.log 'home'
course: Ember.Route.extend
route: '/course'
connectOutlets: (router) ->
console.log 'course'
$ ->
App.initialize()
# after executing: App.router.transitionTo('course')
course
home
# and the current url is changed from "/" to "/course"
# the problem is that, "home" should not be printed here, and the url is changed
# incorrectly, it should be "/#/course"
# then execute: App.router.transitionTo('home')
# nothing happens
# then transition to course again: App.router.transitionTo('course')
course
# and the url is changed from "/course" to "/course#/course"
# then transition to home: App.router.transitionTo('home')
home
# and the url is changed to "/course#"
@mehulkar
Copy link

mehulkar commented Aug 4, 2012

  Router: Ember.Router.extend
    location: 'hash'

    root: Ember.Route.extend
      home: Ember.Route.extend
        route: "/"
        connectOutlets: (router) ->
          console.log 'home'

      course: Ember.Route.extend
        route: '/course'
        connectOutlets: (router) ->
          console.log 'course'

@mehulkar
Copy link

mehulkar commented Aug 4, 2012

Router: Ember.Router.extend
    location: 'hash'

    root: Ember.Route.extend
      home: Ember.Route.extend
        route: "/"
        some_action: Ember.Route.transitionTo('root.course')
        connectOutlets: (router) ->
          console.log 'home'

      course: Ember.Route.extend
        route: '/course'
        connectOutlets: (router) ->
          console.log 'course'

@xhh
Copy link
Author

xhh commented Aug 4, 2012

It turns out not to be ember's problem, I forgot to remove jquery.history.js in my project. Stupid me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment