Created
December 12, 2018 14:17
-
-
Save mistahenry/80d1b9edac21cfd75e84b8c63125d8cb to your computer and use it in GitHub Desktop.
Explicit Query Params Help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
queryParams: ['foo', 'bar'], | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {helper} from '@ember/component/helper'; | |
import Object from '@ember/object'; | |
import {assign} from '@ember/polyfills'; | |
export function explicitQueryParams(params, hash) { | |
let values = assign({}, hash); | |
values._explicitQueryParams = true; | |
return Object.create({ | |
isQueryParams: true, | |
values, | |
}); | |
} | |
export default helper(explicitQueryParams); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL, | |
_hydrateUnsuppliedQueryParams(state, queryParams) { | |
if (queryParams._explicitQueryParams) { | |
delete queryParams._explicitQueryParams; | |
return queryParams; | |
} | |
return this._super(state, queryParams); | |
} | |
}); | |
Router.map(function() { | |
this.route('test'); | |
this.route('redirect-route'); | |
}); | |
export default Router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { explicitQueryParams } from '../helpers/explicit-query-params'; | |
export default Ember.Route.extend({ | |
beforeModel(transition){ | |
transition.abort(); | |
this.transitionTo('test', {queryParams: { _explicitQueryParams: true, foo: 'redirectFoo' }}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.1", | |
"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.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment