Skip to content

Instantly share code, notes, and snippets.

@emattias
Forked from bobisjan/controllers.index.js
Last active March 2, 2023 14:44
Show Gist options
  • Save emattias/37a3c415c0d48a37bdee375145d218f9 to your computer and use it in GitHub Desktop.
Save emattias/37a3c415c0d48a37bdee375145d218f9 to your computer and use it in GitHub Desktop.
urlFor vs generateURL
import Ember from 'ember';
export default Ember.Controller.extend({
routerService: Ember.inject.service('router'),
routingService: Ember.inject.service('-routing'),
queryParams: ['page'],
page: 0,
});
import Ember from 'ember';
export default Ember.Controller.extend({
routerService: Ember.inject.service('router'),
routingService: Ember.inject.service('-routing'),
urlByRouter: Ember.computed(function() {
return this.get('routerService').urlFor('index');
}),
urlByRoutingWithoutEmptyObject: Ember.computed(function() {
return this.get('routingService').generateURL('index', []);
}),
urlByRoutingWithEmptyObject: Ember.computed(function() {
return this.get('routingService').generateURL('index', [], {});
})
});
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('index', {path: ''}, function () {
this.route('sub-route');
});
});
export default Router;
<LinkTo @route="index.sub-route" @query={{hash page=3}}>Go to sub route with page=3</LinkTo>
{{outlet}}
<dl>
<dt>URL by Router Service</dt>
<dd>{{urlByRouter}}</dd>
<dt>URL by Routing Service (without empty queryParams object)</dt>
<dd>{{urlByRoutingWithoutEmptyObject}}</dd>
<dt>URL by Routing Service (with empty queryParams object)</dt>
<dd>{{urlByRoutingWithEmptyObject}}</dd>
</dl>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment