Используя новые Тлеющие угли RouterV2, как вы немедленно перенаправляете к другому государству от состояния индекса?

Что я имею до сих пор:

App = Ember.Application.create({
    LOG_TRANSITIONS: true
});


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


App.ApplicationRoute = Ember.Route.extend({
    redirect: function() {
        this.transitionTo('edit');
    },
    events: {
        startEdit: function( context ){
            this.transitionTo( 'edit' );
        }
    }
})

App.EditRoute = Ember.Route.extend({
    init: function(){
        this._super()
        console.log('EditRoute')
    },
});

Рули:

<script type="text/x-handlebars" data-template-name = 'application'>
    Hello World
    {{ outlet main }} 
</script>

<script type="text/x-handlebars" data-template-name = 'edit'>
    <div class = 'edit-background'> Edit State: {{ title }} </div>
</script>

I have four questions:

  1. When I open the application it just remains in the home page, is the redirectTo hook suppose to immediately redirect you to another state?

  2. In addition, I have this events hash in AplicationRoute per suggestion from here: How to programmatically transition between routes using Ember.js' new Router. but I read through the answers and still am not sure how you are supposed to use it.

  3. How do I test the router on the console? before you could navigate between the states by calling transitionTo commands, what do I do now?

  4. For some odd reason, my application template seem to rendered twice, as in there are two 'Hello World' up there, and when try to add something like:

  5. {{#linkTo edit}}edit{{/linkTo}}

I get this error:

'Uncaught TypeError: Cannot read property 'container' of undefined   --  ember.js:2223' 
2
nl ja de

1 ответы

Это - то, как вы первоначально загрузили бы editView/route/template на прикладном запуске:

Маршрутизатор

App.Маршрутизатор.map(function(match){
  match('/').to('application',function(match){
    match('/').to('edit')
  })
})

ApplicationTemplate

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

EditTemplate

<script type="text/x-handlebars" data-template-name="edit">
    I am embedded! 
</script>

EditRoute

EditRoute = Ember.Route.extend({
  renderTemplates:function() {
      this.render('edit', {
      into:'application'
   });
})
2
добавлено
Ember_js
Ember_js
153 участник(ов)

Cообщество Ember.js