Search code examples
meteorflow-router

With Flow Router how to re-execute a function upon visitng the page?


I have set some functions in the template's onRendered hook like this :

Template.PanelLayout.onRendered(function() {
    Tracker.autorun(function() {
        if (ready.get()) {
            page = Pages.findOne({
                slug: 'about'
            });
            tinymce.init({
                selector: "#pageContent",
                height: 400
            });
            tinymce.get('pageContent').setContent(page.content);
        }
    });
});

If I visit that page directly or reload that page these functions will work. But if I visit it by just clicking a link in the navigation, the functions won't load. How can I fix this?


Solution

  • The short answer is you can't because this is how FlowRouter works: FlowRouter docs

    For a single interaction, the router only runs once. That means, after you've visit a route, first it will call triggers, then subscriptions and finally action. After that happens, none of those methods will be called again for that route visit.

    What you are doing seems to be more suited for Meteor's Template helper