简体   繁体   English

emberjs(1.0rc1)嵌套路由,但在父级时呈现默认子级路由

[英]emberjs (1.0rc1) nested routes but render default child route when at parent

I have an ember app with a home page showing two links: 'sign in' and 'request invite'. 我有一个ember应用程序,其主页显示两个链接:“登录”和“请求邀请”。

Each link goes to a nested route under the parent ( index ) route, rendering into the {{outlet}} of the index route. 每个链接进行到父(下一个嵌套路由index )途径,渲染到{{outlet}}所述的index路由。 It is working like so: 它的工作方式如下:

  • / : renders index into application outlet / :将index呈现到应用程序出口
  • /sign_in : renders index stuff then renders index/sign_in into index template's outlet /sign_in :呈现索引内容,然后将index/sign_in呈现到索引模板的出口
  • /request_invite : renders index stuff then renders index/request_invite into index template's outlet /request_invite :呈现索引内容,然后将index/request_invite呈现到索引模板的出口

This works fine, but what I'd like to do is have the 'sign in' template rendered into the index outlet by default. 这可以正常工作,但是我想做的是默认情况下将“登录”模板呈现到index输出中。 So the first bullet above would change to be like so: 因此,上面的第一个项目符号将变为:

  • / : renders index into the {{outlet}} and renders index/sign_in into index template's outlet / :将index呈现到{{outlet}} 并将 index/sign_in呈现到索引模板的出口中

templates 范本

<script type="text/x-handlebars" data-template-name="application">
  <h1>application</h1>
  {{#linkTo "index"}}index{{/linkTo}}
  {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name='index'>
  <h2>index</h2>
  {{#linkTo "index.sign_in"}}Sign in{{/linkTo}}
  |
  {{#linkTo "index.request_invite"}}Request Invite{{/linkTo}}
  {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name='index/sign_in'>
  <h3>index/sign_in</h3>
</script>

<script type="text/x-handlebars" data-template-name='index/request_invite'>
  <h3>index/request_invite</h3>
</script>

routes 路线

App = Ember.Application.create();

App.Router.map(function() {
  this.resource("index", function() {
    this.route("sign_in");
    this.route("request_invite");
  });
});

Here is a jsbin with the above code . 这是带有上面代码jsbin

When it first loads it doesn't display the index/sign_in or index/request_invite template. 首次加载时不会显示index/sign_inindex/request_invite模板。 I'd to show that index/sign_in template by default. 我将默认显示该index/sign_in模板。

You could declare the IndexRoute explicitly and implement the redirect hook: 您可以显式声明IndexRoute并实现重定向挂钩:

App.IndexRoute = Ember.Route.extend({
  redirect : function(){
    this.transitionTo("index.sign_in");
  }
});

Update: Using a Route other named then index ( JS Bin Link ) 更新:使用其他命名的路由然后使用索引( JS Bin Link

App = Ember.Application.create();

App.Router.map(function() {
  this.resource("main", function() {
    this.route("sign_in");
    this.route("request_invite");
  });
});
App.IndexRoute = Ember.Route.extend({
  redirect : function(){
    this.transitionTo("main");
  }
})
App.MainIndexRoute = Ember.Route.extend({
  redirect : function(){
    this.transitionTo("main.sign_in");
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM