Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Last active May 1, 2019 23:47
Show Gist options
  • Save NullVoxPopuli/e0488ad92af7ce0d6a99f85e7fb73bcf to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/e0488ad92af7ce0d6a99f85e7fb73bcf to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
export default Ember.Controller.extend({
router: service(),
currentURL: computed('router.currentURL', function() {
return this.router.currentURL;
}),
});
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('my-route');
this.route('my-routeA', function() {
this.route('my-sub-route');
});
});
export default Router;
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Route.extend({
router: service(),
// navigatee to my-routeA or my-sub-route, and then back to
// my-route, and you'll see the previousURL
setupController() {
console.log('previous URL:', this.router.currentURL);
}
});
<h1>Getting URL from the router service</h1>
<br>
<br>
{{outlet}}
currentURL: {{this.currentURL}}
<br>
<br>
{{#link-to 'my-route'}}
my-route
{{/link-to}}
|
{{#link-to 'my-routeA'}}
my-routeA
{{/link-to}}
|
{{#link-to 'my-routeA.my-sub-route'}}
my-sub-route
{{/link-to}}
{
"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