Addon to set title & meta tags in your EmberJS application
ember install ember-meta-meta
Set desired metas in your controller setup :
export default Ember.Route.extend({
afterModel() {
this.get('meta').update({
title: 'This Is News Title',
description: 'This Is News Description',
'og:image': 'https://exemple.net/latest-news.png',
'twitter:author': '@j15e'
});
}
});
Will result into this HTML (open graph metas are using property automatically) :
<title>This Is News Title</title>
<meta name="description" content="This Is News Description">
<meta property="og:image" content="https://exemple.net/latest-news.png">
<meta name="twitter:author" content="@j15e">
Title & metas are set only on didTransition
in case the route would be canceled.
Note: Open Graph tags, for sharing on Facebook or Twitter, will not correctly work without using FastBoot or some sort of server side rendering. All Google tags and data will work fine though because Google executes the JS.
You can use an instance initializer to add the following:
defaultTitle
: Default title set when none is provided by route.@title(value)
: Override the title function to append, prefix, etc.
Just run:
ember g instance-initializer after-meta
Then in the resulting initializer, do the following:
export function initialize(appInstance) {
const meta = appInstance.lookup('service:meta');
meta.set('defaultTitle', 'My Custom Default Title');
meta.reopen({
title: function(value){
return value + ' - My Website';
}
});
}
export default {
after: 'meta',
name: 'after-meta',
initialize
};
Use GitHub issues for questions, issues and feature requests.
See CONTRIBUTING.md for more details on contributing and running test.
Jean-Philippe Doyle Jimmy Bourassa