Search code examples
ember.jsember-cli

Ember.js: App.register undefined in app.js


I got a deprecation message when running my app: DEPRECATION: Using the Ember.Location.registerImplementation is no longer supported. Register your custom location implementation with the container instead.. The code is in the app.js.

It is for the hashbang functionality, and I saw someone already written a nice implementation for that: https://stackoverflow.com/a/23055007/1153884

So I literally copied and pasted that code. But after fiddling I could not get it to work. It is because App.register trows an error: Uncaught TypeError: undefined is not a function enter image description here

I have also tested with App.__container__.register. However that does also not work. Is there something changed with the latest Ember CLI that I am not aware of?


Solution

  • Ember CLI doesn’t use App as a global namespace, it uses ES6 modules.

    You can create a new initializer in app/initialzers:

    export default {
      name: 'hashbang',
      initialize: function(container, application) {
        // your code here
      }
    }
    

    The initializer is passed the container as a parameter.