Skip to content

Instantly share code, notes, and snippets.

@buschtoens
Last active July 30, 2018 14:30
Show Gist options
  • Save buschtoens/69dd1a79a3d8d8301d00c89370c347ef to your computer and use it in GitHub Desktop.
Save buschtoens/69dd1a79a3d8d8301d00c89370c347ef to your computer and use it in GitHub Desktop.
RouterService: rootURL inconsistencies
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
export default Controller.extend({
router: service(),
urlFor: computed(function() {
return this.router.urlFor(this.router.currentRouteName);
}),
actions: {
transitionTo(url) {
this.router.transitionTo(url);
}
}
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: '/some/prefix/'
});
Router.map(function() {
});
export default Router;
<dl>
<dt>currentRouteName</dt>
<dd>'{{router.currentRouteName}}'</dd>
<dt>currentURL</dt>
<dd>'{{router.currentURL}}'</dd>
<dt>urlFor(currentRouteName)</dt>
<dd>'{{urlFor}}'</dd>
<dt>rootURL</dt>
<dd>'{{router.rootURL}}'</dd>
</dl>
Works:
<button {{action "transitionTo" currentURL}}>
Navigate to currentURL: '{{currentURL}}'
</button>
<br>
Works:
<button {{action "transitionTo" "/"}}>
Navigate to: '/'
</button>
<br>
Broken:
<button {{action "transitionTo" urlFor}}>
Navigate to urlFor(currentRouteName): '{{urlFor}}'
</button>
{
"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