Skip to content

Instantly share code, notes, and snippets.

@kumkanillam
Forked from cibernox/controllers.application.js
Last active January 20, 2017 17:09
Show Gist options
  • Save kumkanillam/862d4acff7bdb79ee318a6c69c07eb2c to your computer and use it in GitHub Desktop.
Save kumkanillam/862d4acff7bdb79ee318a6c69c07eb2c to your computer and use it in GitHub Desktop.
Router Service Miguel Camba
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
router: Ember.inject.service(),
actions: {
goToRoute(routeName) {
this.get('router').transitionTo(routeName);
}
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('foo');
this.route('bar');
});
export default Router;
<h1>Welcome to {{appName}}</h1>
<button onclick={{action "goToRoute" "foo"}}>Go to foo</button>
<button onclick={{action "goToRoute" "bar"}}>Go to bar</button>
<button onclick={{action "goToRoute" "index"}}>Go to main</button>
<br>
(current route is <strong>{{router.currentRouteName}}</strong>)
<br>
(current URL is <strong>{{router.currentURL}}</strong>)
<br>
(location is <strong>{{router.location}}</strong>)
<br>
(rootURL is <strong>{{router.rootURL}}</strong>)
<br>
<br>
{{outlet}}
<br>
<br>
<h1>This is route bar</h1>
<h1>This is route foo</h1>
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {
"ember-routing-router-service": true
}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "canary",
"ember-data": "2.11.0",
"ember-template-compiler": "canary",
"ember-testing": "canary"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment