Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Last active August 8, 2019 18:56
Show Gist options
  • Save knownasilya/4e86b04b5075e28d5e458cd57a169f0c to your computer and use it in GitHub Desktop.
Save knownasilya/4e86b04b5075e28d5e458cd57a169f0c to your computer and use it in GitHub Desktop.
import EmberRouter from '@ember/routing/router';
import { inject as service } from '@ember/service';
import config from './config/environment';
export default class Router extends EmberRouter {
@service metrics;
@service router;
@service fastboot;
@service headData;
location = config.locationType;
rootURL = config.rootURL;
init() {
super.init(...arguments);
this.on('routeDidChange', () => {
if (!this.fastboot.isFastBoot) {
// calculate data
let data = {
page: this.router.currentURL
};
// send to tracking service
this.metrics.trackPage(data);
}
// set head data for fastboot & opengraph
this.set('headData.ogUrl',`...${this.router.currentURL}`);
});
}
}
Router.map(function() {
// routes here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment