Ember - 在浏览器上刷新重定向到以前的控制器?

时间:2018-06-04 08:54:56

标签: ember.js

我有一个ember应用程序。 路线设置如。

customer 
customer/view/:customerId 
customer/dashboard 
customer/device-sharing

客户/仪表板页面显示一个组件,一个表,其中包含#linkto helper和route customer.device-sharing

这是按预期工作的。 问题是,一旦在设备共享路线上,如果我在浏览器上点击刷新按钮,应用程序将被重定向到仪表板路线。

编辑:

router.js:

this.route('customers', function() {
  this.route('index', {path: '/'});
  this.route('view', {path: '/view/:device_id'});
  this.route('dashboard', {path: '/dashboard/:customer_id'});
  this.route('device-sharing', {path: '/device-sharing'});
});

出现问题的是,在customer.js路由文件的afterModel函数中,我们使用transitionTo转到仪表板。

afterModel(model) {
  model = model || [];
  if (model.length === 1) {
    console.log('Route parent');
    this.transitionTo('customers.dashboard', this.get('paramValue'));
  }
}

有没有办法检查设备共享子路由是否处于活动状态,以便我们可以阻止transitionTo调用。

此致

依禅

1 个答案:

答案 0 :(得分:0)

You probably want to move your model and afterModel to your customers/index route to get the behavior that you're really after. Without seeing more of the code, it's a bit of a guessing game though.

You could use the currentRouteName method on the RouterService to check decide whether to transition or not, but I suspect that would be working around an incorrect design and storing up trouble for yourself down the line.