Flow router don't reload with same url and different parameters


#1

Hi I have this definition of task route:


authenticatedRoutes.route('/tasks/:_id', {
    name: 'task',
    action: function(params) {
        console.log("Yeah! We are on the task:", params._id);

        BlazeLayout.render('Default', {yield: 'Task'});
    }
});

My view have a sidebar where is the list of tasks and the selected task in bigger panel.
For some reason when select another task the view is not reloaded. Only when i refresh manually the browser it is.


#2

I think your problem here is in the template of selected task where you get your param _id. My guess is that you didn’t put your FlowRouter.getParam("_id") inside an autorun. Mind sharing your template for selected task?


#3

@ngochenbang I have two templates, one for the sidebar and another to show the task that includes de sidebar:

TasksSidebar:

<template name="TasksSidebar">
    <div id="sidebar" class="col-xs-12 col-sm-3 col-md-4 col-lg-4">
        <h4>Tareas Disponibles</h4>
        <a class="btn btn-primary btn-block" href="{{pathFor 'createTask'}}">Crear</a>
        <ul class="list-group">
            {{#each tasks}}
                <li class="list-group-item">
                    {{title}}
                    <a href="{{pathFor 'task' _id=_id}}" class="pull-right">
                        <span class="glyphicon glyphicon-play"></span>
                    </a>
                </li>
            {{/each}}
        </ul>
    </div>
</template>

Task template:

<template name="Task">
    <div class="row">
        {{> TasksSidebar}}

        {{#with task}}
            <div id="dashboard" class="col-xs-12 col-sm-9 col-md-6 col-lg-6">
                {{#if hasProyect}}
                    <a id="startProyect" class="btn btn-primary pull-right">Iniciar Proyecto</a>
                {{else}}
                    <a id="continueProyect" class="btn btn-primary pull-right">Ir al Proyecto</a>
                {{/if}}
                <h4>Tarea: {{title}}</h4>
                <h4>Descripcion</h4>
                <p>{{description}}</p>
            </div>
        {{/with}}
    </div>
</template>

#4

I mean your template.js file :sweat_smile:


#5

Jajaja here you have:

Template.Task.onCreated(function() {
    Template.instance().subscribe('aTask', FlowRouter.current().params._id);
});

Template.Task.helpers({
    task: function() {
        var taskId = FlowRouter.current().params._id;
        return Tasks.findOne(taskId);
    },

    hasProyect: function() {
        return false;
    }
});


#6

that is non-reactive, you need to replace it with FlowRouter.getParam("_id")