【发布时间】:2018-06-18 14:06:09
【问题描述】:
我有一个带有多个路由的 Ember 应用程序,我想在每次用户进行转换时将页面滚动到顶部。问题是我不想在每条路由的didTransitionmethod 上复制相同的代码。
那么,有没有一种方法可以让我观察所有路线转换并在一个地方执行(声明)一个动作?
换一种说法:如果我有一个父路由,我可以向它的所有子路由触发相同的操作吗?
我目前的解决方案是在每条路线的 didTransition 方法上触发操作,如下所示:
//router.js
Router.map(function() {
this.route('login');
this.route('portal',{ path:'/'}, function() {
this.route('clientes');
this.route('convite');
this.route('usuario', function() {
this.route('view', { path: '/:id' });
});
});
//everyChildren.route.js
didTransition(){
this.super(...arguments);
Ember.$("html, body").animate({ scrollTop: 0 }, "slow");
}
有没有办法做到这一点?
PS:。我正在使用 Ember 版本 2.14.0
【问题讨论】:
-
听起来你在找ember-router-scroll
标签: ember.js