Is there an easy way to store queries between route changes in IR?


#1

A user comes to my site at example.com/?referrerCode=XXX. I’d like to use XXX when the user signs up.

When he switches routes though, the query part of the route disappears, and by the time they sign up I’ve lost the referrerCode.

Is there an easy way to get around this problem?

Thanks


#2

You could just save it locally in a temporary fashion for the duration of their visit and just reference whenever you need it. You could use a global reactive variable like Session.


#3

Yeah. I tried taking that approach.

I was using this pattern from the user-accounts package:

AccountsTemplates.addField({
  _id: 'referrerCode',
  type: 'hidden'
});

Which expects referrerCode in the query, so was wondering if there was an easy way to keep it in the query.


#4

Ah I see. Unfortunately I can’t help then, I’m not that familiar with IR.


#5

Well this is the code from the user-accounts-core package that was making it work for me. I’ll just set the field myself from the saved variable.

AT.prototype.atInputRendered = function(){
    var fieldId = this.data._id;
    var queryKey = this.data.options && this.data.options.queryKey || this.data._id;
    var inputQueryVal = Router.current().params.query[queryKey];
    if (inputQueryVal)
        this.$("input#at-field-" + fieldId).val(inputQueryVal);