Ember 的 currentPath 和 currentRouteName 始终未定义

Ember's currentPath and currentRouteName are always undefined

本文关键字:未定义 currentRouteName currentPath Ember      更新时间:2023-09-26
MyEmberApp.ApplicationRoute = Ember.Route.extend({
  beforeModel: function() {
    console.log(this);
    console.log(this.controllerFor('application').get('currentPath')); // Undefined.
    console.log(this.controllerFor('application').currentPath); // Undefined.
    // console.log(this.controller.currentRouteName); // Undefined.
    // console.log(Mars.__container__.lookup("controller:application").get("currentRouteName")); // Undefined.
    // console.log(this.controllerFor("application").get("currentPath")); // Undefined.
    // console.log(this.controllerFor("application").get("currentRouteName")); // Undefined.
    this.transitionTo(THE ROUTE NAME I FIND...);
  }
});

我做错了什么?甚至官方文档也说我必须这样做 http://emberjs.com/guides/understanding-ember/debugging/。

文档未能指定您需要在 ApplicationController 上手动创建此属性。

MyEmberApp.ApplicationController = Ember.Controller.extend({
  currentPath: 'test12'
});

在 beforeModel hook 上,您还没有准备好控制器。尝试挂机设置控制器。

setupController(controller, model) {
  this._super(controller, model);
  debugger;
},