Created
July 16, 2015 10:41
-
-
Save avimar/da2ed1298f31751cf5f5 to your computer and use it in GitHub Desktop.
Example of riotj's 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
<auth> | |
<login if={'login'==opts.action || 'logout' == opts.action} action={opts.action}></login> | |
<register if={'register' == opts.action}></register> | |
<change-pass if={'verifyEmail' == opts.action || 'changePass' == opts.action} action={opts.action} uid={opts.uid} data={opts.data}></changePass> | |
<script> | |
console.log(opts.action); | |
if(opts.action=='login' && Cookies.get('apiKey')) riot.route('myAccount'); | |
if(opts.action=='register' && Cookies.get('apiKey')) riot.route('myAccount'); | |
else if(opts.action=="" && Cookies.get('apiKey')) riot.route('myAccount'); | |
</script> | |
</auth> |
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
<main id='main'></main> | |
<script src="bower_components/jquery/dist/jquery.min.js"></script> | |
<script src="bower_components/riot/riot+compiler.min.js"></script> | |
<script src="js/auth.tag" type="riot/tag"></script> | |
<script> | |
var currentTag = null | |
function mount (tag, options) { | |
currentTag && currentTag.unmount(true) | |
currentTag = riot.mount('#main', tag, options) | |
if(currentTag && currentTag[0]) currentTag=currentTag[0]; | |
} | |
function router (section, action, uid, data) { | |
console.log("executed route callback with: " + section +' / '+ action +' / '+ uid + ' / ' + data) | |
if(""==section && !Cookies.get('apiKey')) mount('auth',{action:"login"}) | |
else if (""==section && Cookies.get('apiKey')) mount('my-account',{}) | |
else if ("auth"==section) mount('auth',{action:action, uid:uid, data:data}) | |
else if ("myAccount"==section) mount('my-account',{}) | |
else if ("my-tag"==section) mount('my-tag',{title:'test'}) | |
else if ("myNumbers"==section) mount('my-numbers',{}) | |
else if ("myCards"==section) mount('my-cards',{}) | |
} | |
riot.route.stop() // clear all the old riot.route callbacks | |
riot.route.start() // start again | |
riot.route(router); | |
riot.route.exec(router); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment