EmberJs: how to use connectOutlet

2019-08-30 05:48发布

问题:

I've created a simple test in which I try to use connectOutlet. However, not much is rendered. Here is my test code: http://jsfiddle.net/jeanluca/53dpA/

Just to summarize the application. I think the problems is inside the following code

App.Router.map(function(match) {
    match('/').to('index');
});     

App.IndexRoute = Em.Route.extend({
    connectOutlets: function(router) {
        router.get('applicationController').connectOutlet('sidebar', 'navigation');
        router.get('applicationController').connectOutlet('content');
    }       
});

Any suggestions what is wrong with this code ?

Also, in almost any example code I find on the web, I see that the App.Router is defined

App.Router = Em.Router.extend({
        enableLogging: true,

        root: Em.Route.extend({

            index: Em.Route.extend({
                route: '/',
                connectOutlets: function(router) {   
    .... etc ....

Because with ember-latest App.Router is already defined, I assume this is the old way of defining the Router ?

回答1:

I see in your fiddle that you are using pre-2. The newest version is pre-4, so I suggest you use that. http://emberjs.com/guides/ is up to date with pre-4.

I have created a fiddle and used your code as a starting point and ended up with what I think is what you tried to accomplish: http://jsfiddle.net/Energiz0r/9Xasr/4/

Basically the connectOutlet is replaced with

this.render('content', {into: 'index', outlet:'content');

And there are alot of other changes in the new route API. Again go through the guides at http://emberjs.com/guides/ to get the full understanding of it all.

Hope this helps!