Riot JS disables all tags on the page and then mounts only one tag, does not work

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'
    }
    //unmount all other panels and mount only the panel that is required
    //TODO: unmount all view panels and mounting only required panel is not working
    //riot.unmount('.viewTag')
    riot.mount(view+'-panel')
    $('.viewTag').hide()
    $(view+'-panel').show()
}

$(document).ready(function () {
    RiotControl.addStore(new AuthStore())
    RiotControl.addStore(new CandidatesStore())
    riot.mount('header')
    //register route change handler
    riot.route(function (collection, id, action) {
        switchView(collection)
    })
    riot.route.exec(function (collection, id, action) {
        switchView(collection)
    })
})
+4
source share
3 answers

The answer to this question is riot.js v2.1.0:

Function

riot.unmount(...)
As I know,

. .

mytag.unmount(true) 

, , :

var viewTag = riot.mount(document.getElementById('viewTag'))
viewTag.unmount(true)

, .

+3

2.3.18

, :

app.currentPage = null;

var goTo = function(page){
  if (app.currentPage) {
    app.currentPage.unmount(true); //unmount and keep parent tag
  }
  app.currentPage = riot.mount(page)[0]; //remember current page
};

riot.route(function() {
  console.info("this page is not defined");
  //do nothing (alternatively go to 404 page or home)
});

riot.route('/inventory', function(){
  goTo('inventory');
});

riot.route('/options', function() {
  goTo('options');
});
+1

I think you are looking riot.util.tags.unmountAll(tags)

How to achieve the goal?

index.html

var tags = [];

some.tag.html

var some = this;
tags.push(some);

unmountAllTags.js

riot.util.tags.unmountAll(tags);
+1
source

All Articles