I use Riot JS and in my index.html, I have 3 custom tags - a title, a login panel and a candidate panel in my body. In my main app.js, in the callback function of $ (document) .ready, I execute the current route and also register the function of the route change handler. In my switchView, I will unmount all user tags, and then try to set only the tag related to the current view. Here is my code. If I unmount, nothing is displayed on the page.
index.html
<body>
<header label="Hire Zen" icon="img/user-8-32.png"></header>
<login-panel class="viewTag" id="loginView"></login-panel>
<candidates-panel id="candidatesView" class="viewTag"></candidates-panel>
<script src="js/bundle.js"></script>
</body>
app.js
function switchView(view) {
if(!view || view === '') {
view = 'login'
}
riot.mount(view+'-panel')
$('.viewTag').hide()
$(view+'-panel').show()
}
$(document).ready(function () {
RiotControl.addStore(new AuthStore())
RiotControl.addStore(new CandidatesStore())
riot.mount('header')
riot.route(function (collection, id, action) {
switchView(collection)
})
riot.route.exec(function (collection, id, action) {
switchView(collection)
})
})
source
share