Skip to content

Instantly share code, notes, and snippets.

@avimar
Created July 16, 2015 10:41
Show Gist options
  • Save avimar/da2ed1298f31751cf5f5 to your computer and use it in GitHub Desktop.
Save avimar/da2ed1298f31751cf5f5 to your computer and use it in GitHub Desktop.
Example of riotj's router
<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>
<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