Search code examples
meteorcoffeescriptcollectionfs

Meteor.js: How to perform action on download link of CollectionFS


Hello I have a template where I have link to download uploaded images:

{{#each uploads}}
            <ul class="list-group">
                <li class="list-group-item">{{original.name}} <a href="{{url download=true}}" class="btn btn-primary downloadUpload" data-uploadid="{{_id}}">Download</a></li>
            </ul>
{{/each}}

The link works normally however today I wanted to perform some actions once the button is clicked, like this:

Template.practicalQuestionTake.events
    'click .downloadUpload': (e, template) ->
        console.log @

But after add that event handler once I click the download link I can download the file however the page breaks (blank page), checking the logs in the console it shows me the error:

"TypeError: router.route is undefined"

Then I tried to return true:

Template.practicalQuestionTake.events
    'click .downloadUpload': (e, template) ->
        console.log @
        true

But same result, then I tried to use preventDefault

Template.practicalQuestionTake.events
    'click .downloadUpload': (e, template) ->
        e.preventDefault()
        console.log @

And now anything happens, I can't download the file and it seems that nothing happens.

How can I perform some actions in the event handler of a download link of CollectionFS?


Solution

  • Hi I did a lot of research, and then found that the problem is an issue of Iron router, for some reason when you have a link that points to an external url all your subscriptions and data contexts are lost so you get a 404 not found page or "TypeError: router.route is undefined"

    This is the issue The solution to this problem: Whenever you have a download link (Amazon S3, dropbox, CollectionFS, etc) use target="_blank" in your link. That sovled my issue =)