-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathapplication.js
More file actions
68 lines (53 loc) · 1.62 KB
/
Copy pathapplication.js
File metadata and controls
68 lines (53 loc) · 1.62 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
59
60
61
62
63
64
65
66
67
68
import { service } from '@ember/service';
import Route from '@ember/routing/route';
import ENV from 'ember-api-docs/config/environment';
import { isDestroying, isDestroyed } from '@ember/destroyable';
export default class ApplicationRoute extends Route {
@service
headData;
@service
legacyModuleMappings;
@service
router;
@service
prerender;
@service
metrics;
@service
routerScroll;
@service
shoebox;
constructor() {
super(...arguments);
if (!this.prerender.isPrerendering) {
this.router.on('routeDidChange', this.trackPage);
/* Hax from https://github.com/DockYard/ember-router-scroll/issues/263
to handle router scroll behavior when the page was initially served
pre-rendered
*/
this.routerScroll.set('preserveScrollPosition', true);
setTimeout(() => {
if (!isDestroying(this) && !isDestroyed(this)) {
this.routerScroll.set('preserveScrollPosition', false);
}
}, 1000);
}
if (this.prerender.isPrerendering) {
this.router.on('routeDidChange', this.storeShoebox);
}
}
storeShoebox = () => {
this.shoebox.store();
};
trackPage = () => {
// this is constant for this app and is only used to identify page views in the GA dashboard
const hostname = ENV.APP.domain.replace(/(http|https)?:?\/\//g, '');
const page = this.router.currentURL;
const title = this.router.currentRouteName ?? 'unknown';
this.metrics.trackPage({ page, title, hostname });
};
async afterModel() {
await this.legacyModuleMappings.initMappings();
return super.afterModel(...arguments);
}
}