In a dictionary, I find two example sentences of the use of "trick":
What's the trick to getting this chair to fold up?
On page 21, some tricks to speed up your beauty routine.
As we know, "to" can use be used as a preposition or as a word before an infinitive. When do we use it as a preposition and when as a word before an infinitive?