Created
July 22, 2014 19:43
-
-
Save jamiebuilds/7814846a9d0e98232573 to your computer and use it in GitHub Desktop.
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
| // Create our Application | |
| var app = new Marionette.Application(); | |
| // Attach a router to it | |
| app.router = new Marionette.Router(); | |
| // Configure our router | |
| app.router | |
| // Each state has a name. This one is profile | |
| .state('profile', { | |
| // Matches the profile URL | |
| url: 'profile', | |
| // The view to render in our region | |
| view: profileView, | |
| // Options to pass to the view. Also accepts a function that returns the options | |
| viewOptions: myViewOptions, | |
| // The controller for this state. | |
| controller: profileCtrl | |
| }) | |
| // Nest views with the dot syntax | |
| .state('profile.settings', { | |
| url: 'profile/settings', | |
| view: settingsView, | |
| // Specify a custom selector for this view instead of the default. | |
| region: '.whatever-selector', | |
| controller: settingsCtrl | |
| }); | |
| // You can also configure it across different files | |
| app.router.state('friends', { ... }); | |
| /* | |
| * Let's examine one of those controllers... | |
| */ | |
| var profileCtrl = Marionette.Controller.extend({ | |
| // A new controller is instantiated everytime you navigate to the route | |
| initialize: function(options) { | |
| // An array of the views for this state | |
| this.views = options.views; | |
| // The model that is passed to each view. Add more data | |
| // to it here if you want to | |
| this.model = options.model; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment