Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Forked from sukima/controllers.application.js
Last active May 25, 2016 00:02
Show Gist options
  • Save knownasilya/1c8b2d38e5077d9d045f1125534eac10 to your computer and use it in GitHub Desktop.
Save knownasilya/1c8b2d38e5077d9d045f1125534eac10 to your computer and use it in GitHub Desktop.
How to routeName
import Ember from 'ember';
export default Ember.Controller.extend({
ui: Ember.inject.service(),
appName: 'Ember Twiddle',
routeNameChanged: Ember.observer('currentRouteName', function () {
var name = this.get('currentRouteName');
this.set('ui.currentRouteName', name);
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
ui: Ember.inject.service()
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('foo');
this.route('bar');
});
export default Router;
import Ember from 'ember';
export default Ember.Service.extend({
wittyRouteTitle: Ember.computed('currentRouteName', function() {
switch (this.get('currentRouteName')) {
case 'index': return 'My index route';
case 'foo': return 'The famous foo route';
case 'bar': return 'Bar anyone?';
default: return 'How do I populate this property?';
}
})
});
<h1>Welcome to {{appName}}</h1>
<p>The ui service says the route is: <em>{{ui.currentRouteName}}</em></p>
<hr>
{{outlet}}
<p>This is the <strong>bar</strong> route</p>
{{#link-to "foo" tagName="button"}}Goto back to foo{{/link-to}}
{{#link-to "index" tagName="button"}}Loop back to index{{/link-to}}
<p>This is the <strong>foo</strong> route</p>
{{#link-to "index" tagName="button"}}Goto back to index{{/link-to}}
{{#link-to "bar" tagName="button"}}Goto bar{{/link-to}}
<p>This is the <strong>{{ui.currentRouteName}}</strong> route</p>
{{#link-to "bar" tagName="button"}}Goto bar{{/link-to}}
{{#link-to "foo" tagName="button"}}Goto foo{{/link-to}}
{
"version": "0.8.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment