Skip to content

Instantly share code, notes, and snippets.

@nruth
Last active July 31, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nruth/78ec49906ceb23669c5796976ee2c8b1 to your computer and use it in GitHub Desktop.
Save nruth/78ec49906ceb23669c5796976ee2c8b1 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
// copy-pasted from the RFC example
// https://github.com/emberjs/rfcs/blob/master/text/0095-router-service.md#new-method-checking-for-active-route
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import { observer } from '@ember/object';
export default Helper.extend({
router: service(),
compute([routeName]) {
// this works
//return this.get('router').isActive(routeName);
// this does not work
// and prevents the more complicated version from the rfc example working when a parameterless route is queried, because the empty context object gets passed in and triggers the bug
// it only seems to happen on nested routes
return this.get('router').isActive(routeName, [], {});
},
didTransition: observer('router.currentRoute', function() {
this.recompute();
})
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('dashboard', {path: '/'}, function() {});
//this.route('wrapper', {path: '/wrapper'}, function() {
//this.route('inner', {path: '/inner'});
//});
});
export default Router;
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<li class="{{if (is-active 'dashboard') 'now-active'}}">
{{#link-to 'dashboard'}}Dashboard{{/link-to}}
</li>
{{!--
<li class="{{if (is-active 'wrapper') 'now-active'}}">
{{#link-to 'wrapper'}}Wrapper{{/link-to}}
</li>
<li class="{{if (is-active 'wrapper.inner') 'now-active'}}">
{{#link-to 'wrapper.inner'}}Wrapper-Inner{{/link-to}}
</li>
--}}
<h1>Wrapper</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment