The fate of the spirit after the death of the body highly depends on the Individual spirit/soul.
Broadly speaking, there are four possibilities:
The soul may go to devaloka/swargaloka or towards the realm of ishta devata, if a person has practiced dharma and devotion through out his life.
The soul may go to pitr loka or realms of manes, if a person has performed dharma, but not much of devotion. If one has practiced dharma and proper death rituals are performed, then high chances that such a person will go to pitr loka.
Those who have committed adharma and harmed many people, will either go to various narakas/hells and then take rebirth into lower creatures like animals or plants to undergo suffering.
At times, when death happens unnaturally or in a sudden improper manner, for example, death through choking, or through accidents or due to black magic etc. especially in cases of painful deaths, the souls may get stuck in earthly realm itself as a spirit.
Well, practice of dharma leads one to higher realms, practice of adharma leads to suffering. That is the broad rule that governs birth, death and rebirth.
In Manu Smriti, Bhagavad Purana, or Garuda Purana you will get more details. Even upanishads speak about devayana and pitryana.