0

私は次のような状態にあります

mysite.com/#/indexこれは初期化時にロードされるデフォルトのページです

他にもサブルートがありますmysite.com/#/aboutmysite.com/#/contact

誰かがmysite.com/#/aboutと入力した場合、サブステートのロードを制御できますか?

4

1 に答える 1

1

ルーターでルート(URL)を定義している限り、Emberルーターはこれを自動的に実行します。

次のようなものは、URL mysite.com/#/aboutが入力されると、自動的に正しい状態に移動します。その状態が開始および終了したときに何が起こるかを制御する場合は、enter()およびexit()関数内でこれを指定します。

App.router = Ember.Router.create({
    enableLogging: true,
    //location: 'history',
    root: Ember.Route.extend({
        home: Ember.Route.extend({
            route: '/',
            redirectsTo: 'index'
        }),
        index: Ember.Route.extend({
            route: '/index',
            connectOutlets: function (router) {
                router.get('applicationController').connectOutlet('index');
            }
        }),
        about: Ember.Route.extend({
            route: '/about',

            enter: function() {
                //stuff
            }

            exit: function() {
                //stuff
            }

            connectOutlets: function (router) {
                router.get('applicationController').connectOutlet('about',);
            }
        })
    })
});
于 2012-11-28T09:54:19.367 に答える