When we use a preposition, we can follow it with the gerund:
With most prepositions this is no problem. However, when we use the preposition to, students often confuse it with the to + infinitive structure.
In the first example, work is a noun and to a preposition; in the second example, work is a verb.
If you do not know whether to is with the infinitive or gerund, try putting a noun after it:
This is acceptable so to is a preposition and must be followed by the gerund.
In the following case, to is not a preposition so we do not follow it with the gerund: