The sefer אמרי שפר here explained in parshas Vayeira in the name of his father that when someone accompanies somebody on the start of their journey, the merit of the one accompanying influences the escortee. See this answer on a previous post for more background.
And just as the merit of a righteous person affects in a positive way the person whom he accompanies, so too the wickedness of a wicked person affects negatively the person whom he escorts. Therefore, when Yisrael went out from Egypt and Pharaoh accompanied them on their way (as the Zohar teaches), his intention was to harm them through his escorting by inclining their hearts to want to return to Egypt. But he thought that they would go by the way of the Philistines since this was the closest route, and thus since his intention was that they should go that way, if they had gone that way they would have been strongly influenced by his wickedness and would have been very much inclined to return to Egypt. Therefore, Hashem led them on a different, circuitous route in the wilderness in order that Pharaoh’s negative influence would be severely weakened since this was not the route that he had in mind.
This is what the posuk means: “And it was when Pharaoh sent the people”, that is, when he accompanied them, Hashem “did not lead them by way of the Philistines, because it was near”, and because it was near it was to this route that Pharaoh had channeled his negative influence, and therefore Hashem was concerned “lest the people reconsider when they see war and return to Egypt”. Therefore Hashem made them go around the wilderness so that Pharaoh’s negative influence was weakened, and thus even though we see later on that they still had an inclination to return, it was not so strong and so Moshe was able to stop them.