In Avengers: Infinity War, Thor gets Stormbreaker, and uses it to summon the Bifrost, bringing him, Rocket and Groot to Wakanda to fight Thanos' troops. But how did Thor know that they were in Wakanda, he didn't even know Wakanda existed, and Heimdall was dead so he couldn't direct him?
There are multiple options
1. Energy Signature
Thor must have tracked the energy signature in the battle with the help of Rocket.
From a similar question in Quora
At the end of the movie in the post credits scene we see Maria Hill and Nick Fury driving in a vehicle discussion an energy signature that it coming from Wakanda, one that is 10 times stronger than the signature from New York “Avengers 1”. Since rocket was with Thor let’s assume he has technology capable of tracking energy signatures in the same way Fury can buy at a much higher capacity. I would say this is the way Thor knew to go to Wakanda. Rocket traced energy signatures all over earth and found the greatest one coming from Wakanda.
2. Spotted Battle
During the battle Thanos army did fly a large number of spaceships just outside Wakanda. It is possible that he and Rocket located these alien ships and decided to go there.
3. Tracked Mind stone
We already knew that Banner traced the Space stone / tessarract using radiation. Thor could have told something about the mind stone that helped Rocket trace it. It is to be noted that Thor knew somethings about the mind stone and has seen it before.
It seems that other uses of the Bifrost have been able to target a person rather than a location, e.g. in the first Thor movie the Destroyer armour and the Asgardians arrive near Thor rather than at a specific location.
It's possible he targeted the Bifrost at Thanos rather than a specific location.
I think there are two aspects to this question, "why did Thor go to Earth?" and then "how did he know to go to Wakanda?" The first is pretty clear and answerable but I'll include it to be complete, the second is still speculation but we can make some educated guesses.
Why did Thor go to Earth?
This is pretty clear cut, we know Thor knows where all the Infinity Stones are except for the Soul Stone which no one knows about because of what he tells the Guardians.
Gamora: How do you know he's not going for one of the other Stones?
Thor: There's six stones out there. Thanos already has the Power Stone because he stole it last week, when he decimated Xandar. He stole the Space Stone from me when he destroyed my ship and slaughtered half my people. The Time and Mind Stones are safe on Earth. They're with the Avengers.
Peter Quill: The 'Avengers'?
Thor: Earth's Mightiest Heroes.
Mantis: Like Kevin Bacon?
Thor: He may be on the team. I don't know. Haven't been there in a while. As for the Soul Stone, well, no one's ever seen that. No one even knows where it is. Therefore, Thanos can't get it. Therefore, he's going to Knowhere. Hence, he'll be getting the Reality Stone. You're welcome.
Avengers: Infinity War
Given the Guardians went to Knowhere that leaves him and his team to go to Earth to check on the state of things there. And of course he knows the Children of Thanos have gone to Earth because Thanos tells them to in front of him.
Thanos: There are two more Stones on Earth. Find them, my children, and bring them to me on Titan.
Proxima Midnight: Father, we will not fail you.
Avengers: Infinity War
This begs the question of why he wouldn't go to Titan? Well he doesn't know if the Avengers have been successful in protecting the Stones yet or not. Better to go to the source of the attack and maybe help in defending the Stones and then onto Titan than go to Titan then to Earth and miss the attack altogether.
How did he know to go to Wakanda?
There's no direct evidence on this one but the Russos by way of the official Avengers twitter kind of answered this one. The answer that was given is more of an answer to the previous question but does answer this too.
@Jason__infinity: How did Thor , rocket & groot know about the battle going on in wakanda ? #VuduViewingParty @Avengers
@Avengers: Thor knows Thanos is going after the Stones, and he knows that there are Stones on Earth, so that's what leads him to Wakanda. - Russo Brothers #InfinityWar #VuduViewingParty
How it leads him to Wakanda isn't specified but we have a couple of options that are most likely, both of which were mentioned in this answer.
He tracked the energy signature. If Hill and Fury can do this, and have been doing it for a few years at least, Rocket should be able to do it easily. He loves his tech and has access to a lot of it from Nidavellir.
Maria Hill: Multiple bogeys over Wakanda.
Nick Fury: Same energy signatures as New York?
Maria Hill: Ten times bigger.
Avengers: Infinity War
Of course it's worth noting that they are tracking this with satellites over Earth but that doesn't mean Rocket, who is smarter and has access to more advanced tech and materials, can't create a handheld device.
They spotted the battle on the way in. There is at least one Q-Ship in orbit around the planet during the Battle of Wakanda right over the place. This lets out the Outrider Dropships into Wakanda which should be somewhat easy to spot. On top of that multiple get let down through the battle so he could have noticed them still going down.