The propagation of solitary waves in nematic liquid crystals in the presence of localised nonuniformities is studied. The nonuniformities can be caused by external electric fields, other light beams, or any other mechanism which results in a modified director orientation in a localised region of the liquid-crystal cell. The net effect is that the solitary wave undergoes refraction and trajectory bending. A general modulation theory for this refraction is developed, and particular cases of circular, elliptical and rectangular perturbations are considered. The results are found to be in excellent agreement with numerical solutions.