-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathrouter.js
More file actions
58 lines (49 loc) · 1.53 KB
/
router.js
File metadata and controls
58 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* eslint-disable ember/classic-decorator-no-classic-methods, ember/no-ember-super-in-es-classes, ember/no-get, ember/no-get-with-default, ember/no-incorrect-calls-with-inline-anonymous-functions, prettier/prettier */
import { get } from '@ember/object';
import { run } from '@ember/runloop';
import EmberRouter from '@ember/routing/router';
import config from 'fastboot-website/config/environment';
import { inject as service } from '@ember/service';
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
@service metrics;
@service fastboot;
didTransition() {
this._super(...arguments);
if (!get(this, 'fastboot.isFastBoot')) {
this._scrollPage();
this._trackPage();
}
}
_scrollPage() {
if (this.fastboot.isFastBoot) {
return;
}
run.scheduleOnce('afterRender', this, () => {
let position = 0;
let hash = window.location.hash;
if (hash) {
let id = hash.split('#')[1];
let el = document.getElementById(id);
if (el) {
position = el.getBoundingClientRect().top;
}
}
window.scrollTo(0, position);
});
}
_trackPage() {
if (this.fastboot.isFastBoot) {
return;
}
run.scheduleOnce('afterRender', this, () => {
let page = document.location.pathname;
let title = this.getWithDefault('currentRouteName', 'unknown');
this.metrics.trackPage({ page, title });
});
}
};
Router.map(function() {
this.route('page', { path: '*path' });
});