1

I have a route defined as:

AS.Router.map(function(){
    this.resource('analytics', {path: '/analytics'}, function(){
        this.route('index', {path: '/'});
        this.route('config', {path: '/config'});
    ); 
});

AS.AnalyticsRoute = Ember.Route.extend({
    redirect: function() {
        this.transitionTo('analytics.index');
    }
});

With above config, I am able to load pages :

/#/analytics

--this loads the analytics/index template

/#/analytics/config

--this loads the analytics/config template

but #/analytics/index doesn't load, it just shows the loading gif image. Here is how my templates look like :

analytics:

{{outlet}}

analytics\index:

index

analytics\config:

config

Is there a way I could make url link to #/analytics/index work too without breaking #/analytics?

Thanks, Dee

4

1 に答える 1

0

resourceルーター マップでを定義する場合analytics.index、 は暗黙的なルートであり、明示的に定義しないでください。デフォルトの動作では、テンプレートは、定義済みの場所にあるテンプレートのアウトレットにanalytics.indexレンダリングされます。analytics{{outlet}}

たとえば、これは期待どおりに機能するはずです。

AS.Router.map(function(){
  this.resource('analytics', {path: '/analytics'}, function(){
    this.route('config', {path: '/config'});
  ); 
});

analytics.indexこれにより、テンプレートがanalyticsテンプレート アウトレットに正しくレンダリングされます。

に移動するときにanalyticsルートに直接アクセスできる必要があり"/"、ユーザーをリダイレクトしたい/analytics場合は、IndexRoute代わりに次のようにリダイレクトする必要があります。

AS.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo('analytics');
  }
});

それが役に立てば幸い。

于 2013-09-03T20:03:27.153 に答える