Last active
December 11, 2015 11:28
-
-
Save boy-jer/4593437 to your computer and use it in GitHub Desktop.
emberjs router V3
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
Adapted from Tchak's code here https://gist.github.com/4511824 | |
//Passing a function instead of route name will setup an anonymous route and assign the function as `redirect` hook. | |
//Passing object instead of route name can be used to redirect for example. | |
App.Router.map(function { | |
this.resource('index', { path: '/'}, function() { | |
if (this.controllerFor('login').get('isSignedIn')) { | |
this.transitionTo('search'); | |
} else { | |
this.transitionTo('signIn'); | |
} | |
}); | |
this.route('search'); | |
this.route('cart'); | |
this.route('tickets'); | |
this.resource('preferences', function() { | |
this.route('index', {path: '/'}, {redirectTo: 'email'}); | |
this.route('email', {path: /'email'}); | |
}); | |
this.route('signIn'); | |
}); |
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
renderTemplate: () -> | |
@render('index') | |
@render('social', {outlet: 'social'}) | |
@render('earnings', {outlet: 'earnings'}) | |
@render('usage', {outlet: 'usage'}) |
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
connectOutlets: (router) -> | |
router.get('applicationController').connectOutlet('index') | |
router.get('indexController').connectOutlet('social', 'social') | |
router.get('indexController').connectOutlet('earnings', 'earnings') | |
router.get('indexController').connectOutlet('usage', 'usage') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment