One way to track ships is using:
Imperial XX-23 S-Thread Tracker
The XX-23 S-Thread tracker was a model of homing beacon used by the Galactic Empire. When the Millennium Falcon escaped from the Death Star, carrying Leia Organa and the battle station's plans to the Rebel base on Yavin 4, the Empire tracked the ship via one such device attached to the freighter's underside. [wookieepedia]
Trackers seems to be pre-installed on bigger ships and The Slave I and TIE Advanced ships can fire homing beacons on to enemy starships with projectile launchers.
If they have an exit vector
In ESB, after the Falcon disappears, Vader commands Admiral Piett to:
Calculate every possible destination along their last know trajectory
Vader clearly cares about what their last trajectory is as well and believes he can find possible destinations from that information.
If ships can be tracked through hyperspace, why do the Imperials need to place a tracking device on the Falcon?
Imagine that Leia had been smart enough to tell Han "hey by the way they probably will try to track us, maybe we should make some decoy jumps/stops first?"
Suddenly, any visual track through hyperspace becomes worthless. [SF StackExchange]
Or they just know where ship is going.