に行(い)く is a grammar construction that is used when someone is going somewhere for the purpose of doing (A). (A) representing the verb that comes before
に行(い)く. As with other uses of
に, this particle is highlighting an end point or goal of ‘going’.
This grammar point is regularly translated as ‘to go in order to (A)’.
If you have already ‘gone’ somewhere for the purpose of doing something, then you would use ‘(A)
に来(き)た’, while at the location.