Basic example of nested routes with some CSS to highlight the active route in the navigation links.
Created
September 17, 2019 23:30
-
-
Save JulianLeviston/0b24cc98412ac1f4786ef833c4b32e1b to your computer and use it in GitHub Desktop.
Ember Twiddle Demo: Simple nested routes
This file contains 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({ | |
actors: null, // this will be set by setupController only once, when the route is entered with an id. | |
}); |
This file contains 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 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 config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('movies', function () { | |
this.route('actors', { path: ':movie_id' }); | |
}); | |
}); | |
export default Router; |
This file contains 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.Route.extend({ | |
model(params) { | |
const actorsByMovie = { | |
1: [ | |
"Mark Hamill", | |
"Carrie Fisher" | |
], | |
2: [ | |
"Liv Tyler", | |
"Elijah Wood" | |
], | |
3: [ | |
"William H Macy", | |
"Frances McDormand" | |
] | |
}; | |
return actorsByMovie[params.movie_id]; | |
}, | |
setupController(controller, model) { | |
this._super(controller, model); | |
// set the actors property of the controller | |
// if it hasn't been set - ie memoize | |
if(Ember.isEmpty(controller.get('actors'))) { | |
controller.set('actors', model) | |
} | |
}, | |
}); |
This file contains 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.Route.extend({ | |
model() { | |
return [ | |
{ id: 1, title: 'Star Wars' }, | |
{ id: 2, title: 'Lord of the Rings' }, | |
{ id: 3, title: 'Fargo' }, | |
]; | |
} | |
}); |
This file contains 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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.active { | |
font-weight: bold; | |
color: navy; | |
} |
This file contains 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.11.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.18.0", | |
"ember-data": "2.18.0", | |
"ember-template-compiler": "2.18.0", | |
"ember-testing": "2.18.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment